/**************************************************************************************************
                JAVA SCRIPT TO PERFORM CLIENT SIDE VALIDATIONS
                
Script Name          : validation.js   
Script Type          : Java Script         
Written By           : Florence Juliet J
Written On           : 08/03/2006
Last Modification On : 08/03/2006
Organization         : Cyber Korp India Pvt Ltd
Web Site             : http://www.corp-corp.com
Description          : Contains functions to perform client side validation 
                       
***************************************************************************************************/

function checkEmpty(curValue,errCtrl,errMsg)
    {
      if(trimString(curValue.value).length==0) 
      {
        document.getElementById(errCtrl).value="Please Provide Your "+errMsg;  // Display Error Message
      }
      else
      {
        document.getElementById(errCtrl).value="";
      }
    }
 

    //--------------->> Function to trim a string <<-----------------------------------------------
    function trimString (str) 
    {
       str = this != window? this : str; // Using Regular Expression 
       return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); 
    }
	
	//Function to StripOut HTML Tags and Script Tags
	function stripHtml()
    {	
		if(typeof(this) == "object")
		{	
			var matches = this.value.match(/&#\d+;?/g);
			if(matches != null)
			{
				for(var i = 0; i < matches.length; i++)
				{
					var replacement = String.fromCharCode((matches[i]).replace(/\D/g,""));
					this.value = this.value.replace(/&#\d+;?/,replacement);
				}
			}	
			this.value = this.value.replace(/<(.|\n)*?>/g,"");
			this.value = this.value.replace(/script( |\t)*?:/gi,"script;");
		}
    }
    
   //--------------->> Function to check textbox empty <<------------------------------------------
    function isEmpty(curCtrl,curCtrlName,nextCtrl,errMsg)
    {
      var curValue=trimString(curCtrl.value); // Trim the string
      if(curValue.length==0) 
      {
        alert("Please Provide Your "+errMsg+" !!!");  // Display Error Message
        document.getElementById(curCtrlName).focus(); 
      }
      else  // Set Focus To Next Control
        document.getElementById(nextCtrl).focus();
    }
    
    //--------------->> Function to check the Key Presses <<---------------------------------------
    function DisplayKey(e,curCtrl,curCtrlName,nextCtrl,errMsg) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if(keycode==9) // If Tab key is pressed
      {
        isEmpty(curCtrl,curCtrlName,nextCtrl,errMsg);// Check for empty     
        return false;
      }
      return true;
    }
    
    //--------------->> Function to check the selectivity of combo <<------------------------------
    function isSelected(ctrlName,ctrlType)
    {
      if(document.getElementById(ctrlName).value=="SELECT")
         alert("Please Select Your "+ctrlType+" !!!");   // Display Error Message
    }  
        
    //--------------->> Function to check Key Stroke for Numeric Value <<--------------------------
    function onlyNumeric(e)
    { //alert(e.keyCode);
      if (e.keyCode) 
      {
      keycode=e.keyCode;
      }
      else
      {
       keycode=e.which;
       }
      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9||keycode==189||keycode==109||(keycode>=96&&keycode<=105)||keycode==35||keycode==36||keycode==46||keycode==37||keycode==39)
       {
        return true;  // Allow only numeric values,hyphen
        }
      else
      {
       return false;
       }
    }
    
    //--------------->> Function to check Key Stroke for Tab Key <<--------------------------------
    function onlyTab(e)
    {
      if (e.keyCode) keycode=e.keyCode;
      else keycode=e.which;
      if(keycode==9)
        return true;  // Allow only tab key
      else return false;
    }
    
    //--------------->> Function to check Key Stroke for Zip Code <<-------------------------------
    function zip(e)
    {
      if (e.keyCode) keycode=e.keyCode;
      else keycode=e.which;
      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9||keycode==189||keycode==109)
        return true;  // Allow only numeric values,hyphen,space
      else return false;
    }
    function clearJobTitle()
    { 
     if(document.getElementById('txtjobtitle2').value=='eg. Programmer, System Analyst, Project Manager')
     { 
       document.getElementById('txtjobtitle2').value='';
       //document.getElementById('txtjobtitle2').className ="textbox";
      // document.getElementById('txtjobtitle2').style.font.fontColor ="blue";
     }
     
    }
        
    //--------------->> Function to check Key Stroke for Phone No <<-------------------------------
    function validPhoneNo(e,curCtrlName)
    {
      if (e.keyCode) keycode=e.keyCode;
      else keycode=e.which;

      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9)
      {
        var phoneNo=document.getElementById(curCtrlName).value;
        if(keycode==8&&(phoneNo.length==4||phoneNo.length==8))
          document.getElementById(curCtrlName).value=phoneNo.substring(0,phoneNo.length-1);

        if(keycode==9)
        {
          if(phoneNo.length==0) // Check Empty
          {
            //alert("Please Provide Your Phone Number !!!");
            return true;
          }  
          else if(phoneNo.length<12) // Check Validity
          {
           //alert("Please Provide Valid Phone Number !!!");
           document.getElementById(curCtrlName).focus();
           return false;
          }  
          return true; 
        }
        return true;  // Allow only numeric values
      }  
      else  return false;
    }
    
    //--------------->> Function to check Key Stroke for Fax <<------------------------------------
    function validFax(e,curCtrlName)
    {
      if (e.keyCode) keycode=e.keyCode;
      else keycode=e.which;
      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9)
      {
        var phoneNo=document.getElementById(curCtrlName).value;
        if(keycode==8&&(phoneNo.length==4||phoneNo.length==8))
          document.getElementById(curCtrlName).value=phoneNo.substring(0,phoneNo.length-1);
        if(keycode==9)
        {
          if(phoneNo.length<12&&phoneNo.length>0) // Check Validity
          {
           alert("Please Provide Valid Data eg xxx-xxx-xxxx !!!");
           document.getElementById(curCtrlName).focus();
           return false;
          }   
        }
        return true;  // Allow only numeric values
      }  
      else  return false;
    }
    
    //--------------->> Function to append Hyphen automatically <<---------------------------------
    function displayHyphen(curCtrlName)
    {
      var phoneNo=document.getElementById(curCtrlName).value;
      if(phoneNo.length==3||phoneNo.length==7) // Add Hyphen after areacode
        phoneNo=phoneNo+"-";
      document.getElementById(curCtrlName).value=phoneNo;
    }
    //--------------->> function to convert first letter capital <<------------------------------------------------------
    function firstLetter(txtVal)
    {
	  var strInput = txtVal.toLowerCase();
      var strOutput ="";
      for(var i=0;i<strInput.length;i++)
      {  if(i==0)
          { strOutput += strInput.substr(0,1).toUpperCase();
          }
          else if(strInput.substr(i-1,1)==" ")
          {  strOutput += strInput.substr(i,1).toUpperCase();
          }
          else
          { 
          strOutput += strInput.substr(i,1).toString();
          }
      }
        return strOutput;
    }
   //---------------------->> Function to remove special character on off-focus of control <<----------------------
   function removeSpecial(curCtrlName)
   { 
		var extNo = document.getElementById(curCtrlName).value;
		extNo = extNo.replace(/[^0-9]/g,"");
		document.getElementById(curCtrlName).value = extNo;
   }
    //--------------->> Function to append Hyphen automatically on Off-focus of control<<---------------------------------
     function addHyphen(curCtrlName)
    { 
		var phoneNo = document.getElementById(curCtrlName).value;
		var strPhone="";
		strPhone = phoneNo.replace(/[^0-9]/g,"");		
        //09feb07 modification starts here
        if(strPhone.length>10)
        {
			strPhone = strPhone.substring(0,10);
        }
        //09feb07 modification ends here           
        if(strPhone.length > 2 )
        { 
			var phoneNo1 = strPhone.substring(0,3);
			strPhone = strPhone.substring(phoneNo1.length,strPhone.length);         
			if(strPhone.length>2)
			{
				var phoneNo2=strPhone.substring(0,3);
				strPhone=strPhone.substring(phoneNo2.length,strPhone.length);             
				if(strPhone.length>3)
				{ 
					var phoneNo3 = strPhone.substring(0,strPhone.length);
					document.getElementById(curCtrlName).value=phoneNo1+"-"+phoneNo2+"-"+phoneNo3;
                 }
                 else{document.getElementById(curCtrlName).value=phoneNo1+"-"+phoneNo2+"-"+strPhone;}
            }
			else
			{document.getElementById(curCtrlName).value=phoneNo1+"-"+strPhone;}
        }
		else 
		{document.getElementById(curCtrlName).value=strPhone;}
		
		if(document.getElementById(curCtrlName).value.length > 12)
		{
			document.getElementById(curCtrlName).focus();
		}
    }
    //--------------->> Check whether state selecte or entered <<----------------------------------
    function isStateEmpty(e,curCtrl,curCtrlName,nextCtrl,drpState) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if(keycode==9) // If Tab key is pressed
      {
        var curValue=trimString(curCtrl.value); // Trim the string
        var stateSelected=document.getElementById(drpState).value;
        if(curValue.length==0&&(stateSelected=='XX'||stateSelected=='SELECT')) 
        {  // Check for empty   
           alert("If you belong to USA Please select your state from combo Otherwise enter your state in the textbox !!!");  // Display Error Message
           document.getElementById(curCtrlName).focus(); 
        }
        else  // Set Focus To Next Control
           document.getElementById(nextCtrl).focus();  
        return false;
      }
      return true;
    }
    
    //--------------->> Set Focus to the control <<------------------------------------------------
    function setFocus(ctrlName)
    {
      document.getElementById(ctrlName).focus();
    }
    
     //--------------->> Open Calendar in new Window <<--------------------------------------------
    function openCalendar(frmName,eltName,left,top)
    {
      result=window.open("../frmCalendar.aspx?FormName="+frmName+"&eltName="+eltName,"CalendarWindow","width=150,height=175,left="+left+",top="+top);
    }
    
    
    //--------------->> Populate Country Code Automatically <<-------------------------------------
  // ccode('dListCountry','txtCountryCode','txtState','dListState','txtFCountryCode')
    function ccode(combo,output1,state,stateCombo,output2)
    {
      var comboValue=document.getElementById(combo).value;
      /*if(document.getElementById(combo).selectedIndex==217)
      {
         document.getElementById(state).disabled=true;
         document.getElementById(stateCombo).options[0].selected=true; 
       }   
      else
      {
         document.getElementById(state).disabled=false;
         document.getElementById(stateCombo).options[55].selected=true; 
         document.getElementById('txtState').value='';
         document.getElementById('txtoutside').value='';
      }*/  
      if(comboValue!="SELECT")
      {
      document.getElementById(output1).value=comboValue;
      document.getElementById(output2).value=comboValue;
      
      }
      else
      {
      document.getElementById(output1).value='';
      document.getElementById(output2).value='';
      }
    }
    
    //--------------->> Populate Mobile Country Code Automatically <<------------------------------
    function mobileCode(phoneCode,MobileCode)
    {
       var code=document.getElementById(phoneCode).value;
       
       document.getElementById(MobileCode).value=code;
       document.getElementById('txtFCountryCode').value=code;
    }
    
    //--------------->> Function to check Domain Match <<------------------------------------------
    function isValidURL(e,curCtrl,curCtrlName,nextCtrl,errMsg,email,errCtrl) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if(keycode==9) // If Tab key is pressed
      {
        var url=document.getElementById(curCtrlName).value;
        if(trimString(url)==""||trimString(url)=="http://www.")
        {
          document.getElementById(errCtrl).value="Please Provide Your Website URL !!!";
          document.getElementById(curCtrlName).focus();
        }   
        else
        {
          document.getElementById(errCtrl).value="";
          var emailID=document.getElementById(email).value;
          var emailDomain=emailID.substring(emailID.indexOf("@")+1,emailID.length);
          emailDomain=emailDomain.toUpperCase();
          var webDomain=url.toUpperCase();
          if(webDomain.indexOf(emailDomain)<=0)
          {
            document.getElementById(errCtrl).value="Please use only your corporate EMail ID and it should match the corporate website domain name";
            document.getElementById(curCtrlName).focus();
            return false;
          }  
          else
          {
            document.getElementById(errCtrl).value="";
          }
          return true;
        }
        return false;
      }
      return true;
    }
    
    //--------------->> Function to check Password Match <<----------------------------------------
    function isPasswordMatch(e,curCtrl,curCtrlName,nextCtrl,errMsg,pwd) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if(keycode==9) // If Tab key is pressed
      {
        var cpwd=document.getElementById(curCtrlName).value;
        var pass=document.getElementById(pwd).value;
        if(trimString(cpwd)=="")
        {
          alert("Please Provide Your Confirmation Password");
          document.getElementById(curCtrlName).focus();
          return false;
        }
        else if(cpwd.toUpperCase()!=pass.toUpperCase())
        {
          alert("Please make sure that your confirmation password matches your password");
          document.getElementById(curCtrlName).focus();
          return false;
        }
        return true;
      }
      return true;
    }
    
    //--------------->> Function to check Zipcode Empty <<-----------------------------------------
    function isZipEmpty(e,curCtrl,curCtrlName,nextCtrl,errMsg) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9||keycode==189||keycode==109)
      {
         if(keycode==9) // If Tab key is pressed
         {
           isEmpty(curCtrl,curCtrlName,nextCtrl,errMsg);// Check for empty     
           return false;
         }
         return true;
      }
      return false;
    }
    
    //--------------->> Function to check textbox empty <<-----------------------------------------
    function isEmptyNew(curCtrl,curCtrlName,nextCtrl,errMsg,errCtrl)
    {
      var curValue=trimString(curCtrl.value); // Trim the string
      if(curValue.length==0) 
      {
        document.getElementById(errCtrl).value="Please Provide Your "+errMsg+" !!!"
        document.getElementById(curCtrlName).focus(); 
      }
      else  // Set Focus To Next Control
      {
        document.getElementById(errCtrl).value=""
        document.getElementById(nextCtrl).focus();
      }  
    }
    
    //--------------->> Function to check the Key Presses <<---------------------------------------
    function DisplayKeyNew(e,curCtrl,curCtrlName,nextCtrl,errMsg,errCtrl) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if(keycode==9) // If Tab key is pressed
      {
        isEmptyNew(curCtrl,curCtrlName,nextCtrl,errMsg,errCtrl);// Check for empty     
        return false;
      }
      return true;
    }
    
    //--------------->> Check whether state selected or entered <<----------------------------------
    
    function isStateEmptyNew(e,curCtrl,curCtrlName,nextCtrl,drpState,errCtrl) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
      if(keycode==9) // If Tab key is pressed
      {
        var curValue=trimString(curCtrl.value); // Trim the string
        var stateSelected=document.getElementById(drpState).value;
        if(curValue.length==0&&(stateSelected=='Other State/Outside USA'||stateSelected=='SELECT'||stateSelected=='Outside USA')) 
        {  // Check for empty   // Display Error Message
           document.getElementById(errCtrl).value="Please Enter State";  
           document.getElementById(curCtrlName).focus(); 
        }
        else  // Set Focus To Next Control
        {
           document.getElementById(nextCtrl).focus();  
           document.getElementById(errCtrl).value="";
        }   
        return false;
      }
      return true;
    }
    
    //--------------->> Function to check Key Stroke for Phone No <<-------------------------------
    function validPhoneNoNew(e,curCtrlName,errCtrl)
    {
      if (e.keyCode) keycode=e.keyCode;
      else keycode=e.which;
      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9)
      {
        var phoneNo=document.getElementById(curCtrlName).value;
        if(keycode==8&&(phoneNo.length==4||phoneNo.length==8))
          document.getElementById(curCtrlName).value=phoneNo.substring(0,phoneNo.length-1);
        if(keycode==9)
        {
          if(phoneNo.length==0) // Check Empty
          {
            document.getElementById(errCtrl).value="Please Provide Your Phone Number !!!";
            document.getElementById(curCtrlName).focus();
            return false;
          }  
          else if(phoneNo.length<12) // Check Validity
          {
           document.getElementById(errCtrl).value="Please Provide Valid PhoneNo(xxx-xxx-xxxx)";
           document.getElementById(curCtrlName).focus();
           return false;
          }  
          else
          {
           document.getElementById(errCtrl).value=""
          }
          return true; 
        }
        return true;  // Allow only numeric values
      }  
      else  return false;
    }
    
    //--------------->> Function to check Key Stroke for Fax <<------------------------------------
    function validFaxNew(e,curCtrlName,errCtrl)
    {
      if (e.keyCode) keycode=e.keyCode;
      else keycode=e.which;
      if((keycode>=48&&keycode<=57)||keycode==8||keycode==9)
      {
        var phoneNo=document.getElementById(curCtrlName).value;
        if(keycode==8&&(phoneNo.length==4||phoneNo.length==8))
          document.getElementById(curCtrlName).value=phoneNo.substring(0,phoneNo.length-1);
        if(keycode==9)
        {
          if(phoneNo.length<12&&phoneNo.length>0) // Check Validity
          {
           document.getElementById(errCtrl).value="Please Provide Valid Data eg xxx-xxx-xxxx !!!";
           document.getElementById(curCtrlName).focus();
           return false;
          }   
        }
        return true;  // Allow only numeric values
      }  
      else  return false;
    }
    //-- 
    function OpenViewProfile(url) { 
		var mywindow;
		 mywindow=window.open('../emp/Emp_view_rs.aspx?RSID='+url,'ViewProfile','width=952,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=yes'); 
		 if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
		 {
			mywindow.moveTo(30,120);
		 }
		}
	function ViewH1BEligProfile(url) { 
		var mywindow;
		 mywindow=window.open('../emp/Emp_s_h1b_elg_view_rs.aspx?RSID='+url,'ViewProfile','width=952,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=yes'); 
		 if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
		 {
			mywindow.moveTo(30,120);
		 }
		}
    function ForwardResume(url)
		{
		var mywindow;
		mywindow=window.open('../emp/Emp_ForwardProfile.aspx?RSID='+url,'ForwardProfile','width=790,height=510,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=no'); 
			if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
			{
				mywindow.moveTo(120,100);
			}
		}
   function OpenApplyJob(url) {  		
		var mywindow;		 
		mywindow=window.open(url,'ApplyJob','width=850,height=600,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=no'); 
			if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
			{
				mywindow.moveTo(100,70);
			}
		}
	function ContactRecruiter(url) {
		var mywindow;		 
		mywindow=window.open(url,'ContactRecruiter','width=850,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=no'); 
			if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
			{
				mywindow.moveTo(100,70);
			}
		}		
   function OpenForwardJob(url) { 
		var mywindow;
		if (document.referrer && document.referrer!="" && document.referrer.indexOf("webmin") > 0)
		{
		   url = url+'&ref=admin';
		}
		mywindow=window.open(url,'ForwardJob','width=750,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=no'); 
			if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
			{
				mywindow.moveTo(150,170);
			}
		}
    
   function OpenCHKAvail(url) { 
		var mywindow;		 
		mywindow=window.open('../emp/Emp_chk_avail.aspx?RSID='+url,'ApplyJob','width=670,height=414,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=no'); 
			if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
			{
				mywindow.moveTo(120,190);
			}
		}  
		
	function OpenAgreement() { 
		//var wleft = (screen.width -450-32) / 2; 
		//var wtop = (screen.height -390-96) / 2; 
		var mywindow;		 
		//mywindow=window.open('agreement.html','Agreement','left=' + wleft + ',top=' + wtop + ',width=780,height=414,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=no'); 
		mywindow=window.open('agreement.html','Agreement','width=780,height=414,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=1,copyhistory=no,resizable=no'); 
			if(!(navigator.userAgent.toLowerCase().indexOf('chrome') >= 0))
			{
				mywindow.moveTo(120,190);
			}
		}  
    
    //--------------->> Function To Allow Only Corporate Email <<----------------------------------
    function isCorporateID(e,curCtrl,nextCtrl,errCtrl) 
    {
      if (e.keyCode) keycode=e.keyCode; // Get the keycode
      else keycode=e.which;   
     if(keycode==9) // If Tab key is pressed
      {
        var email=document.getElementById(curCtrl).value;
        var emailDomain=email.substring(email.indexOf("@")+1,email.length);
        emailDomain=emailDomain.toLowerCase();
        var emailID = email.substring(0,email.indexOf("@"));
        emailID=emailID.toLowerCase();
        var str=emailID.indexOf("yahoo");
        if(str==-1)
        str=emailID.indexOf("gmail");
        if(str==-1)
        str=emailID.indexOf("rediff");
        if(str==-1)
        str=emailID.indexOf("rediffmail");
        if(str==-1)
        str=emailID.indexOf("hotmail");
        if(str==-1)
        str=emailID.indexOf("dice");
        if(str==-1)
        str=emailID.indexOf("monster");
        if(str==-1)
        str=emailID.indexOf("google");
         if(str==-1)
        str=emailID.indexOf("ymail");
         if(str==-1)
        str=emailID.indexOf("rocketmail");
            
        if( str!=-1)
        { 
          document.getElementById(errCtrl).innerHTML="<- Use Only Corporate EMail ID";
          document.getElementById(curCtrl).select();
          return false;
        }
       else if(emailDomain=="yahoo.com"||emailDomain=="yahoo.co.in"||emailDomain=="gmail.com"||emailDomain=="msn.com"||emailDomain=="google.com"||emailDomain=="google.co.in"||emailDomain=="hotmail.com"||emailDomain=="rediff.com"||emailDomain=="rediffmail.com"||emailDomain=="vsnl.com"||emailDomain=="aol.com")
        {
          document.getElementById(errCtrl).innerHTML="<- Use Only Corporate EMail ID";
          document.getElementById(curCtrl).select();
           return false;
        }
            
       else
        {
          document.getElementById(errCtrl).value="";
         document.getElementById(nextCtrl).focus();
        }
       return false;
     }
     return true;
    } 
    /*Round Corner Script Starts Here*/
    function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
      this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

function Rounded(selector,wich,bk,color,opt){
var i,prefixt,prefixb,cn="r",ecolor="",edges=false,eclass="",b=false,t=false;

if(color=="transparent"){
    cn=cn+"x";
    ecolor=bk;
    bk="transparent";
    }
else if(opt && opt.indexOf("border")>=0){
    var optar=opt.split(" ");
    for(i=0;i<optar.length;i++)
        if(optar[i].indexOf("#")>=0) ecolor=optar[i];
    if(ecolor=="") ecolor="#666";
    cn+="e";
    edges=true;
    }
else if(opt && opt.indexOf("smooth")>=0){
    cn+="a";
    ecolor=Mix(bk,color);
    }
if(opt && opt.indexOf("small")>=0) cn+="s";
prefixt=cn;
prefixb=cn;
if(wich.indexOf("all")>=0){t=true;b=true}
else if(wich.indexOf("top")>=0) t="true";
else if(wich.indexOf("tl")>=0){
    t="true";
    if(wich.indexOf("tr")<0) prefixt+="l";
    }
else if(wich.indexOf("tr")>=0){
    t="true";
    prefixt+="r";
    }
if(wich.indexOf("bottom")>=0) b=true;
else if(wich.indexOf("bl")>=0){
    b="true";
    if(wich.indexOf("br")<0) prefixb+="l";
    }
else if(wich.indexOf("br")>=0){
    b="true";
    prefixb+="r";
    }
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    if(edges) AddBorder(v[i],ecolor);
    if(t) AddTop(v[i],bk,color,ecolor,prefixt);
    if(b) AddBottom(v[i],bk,color,ecolor,prefixb);
    }
}

function AddBorder(el,bc){
var i;
if(!el.passed){
    if(el.childNodes.length==1 && el.childNodes[0].nodeType==3){
        var t=el.firstChild.nodeValue;
        el.removeChild(el.lastChild);
        var d=CreateEl("span");
        d.style.display="block";
        d.appendChild(document.createTextNode(t));
        el.appendChild(d);
        }
    for(i=0;i<el.childNodes.length;i++){
        if(el.childNodes[i].nodeType==1){
            el.childNodes[i].style.borderLeft="1px solid "+bc;
            el.childNodes[i].style.borderRight="1px solid "+bc;
            }
        }
    }
el.passed=true;
}
    
function AddTop(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingTop=0;
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,bc,cn){
var i,lim=4,d=CreateEl("b");

if(cn.indexOf("s")>=0) lim=2;
if(bc) d.className="artop";
else d.className="rtop";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=CreateEl("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    if(bc) x.style.borderColor=bc;
    d.appendChild(x);
    }
el.style.paddingBottom=0;
el.appendChild(d);
}

function CreateEl(x){
if(isXHTML) return(document.createElementNS('http://www.w3.org/1999/xhtml',x));
else return(document.createElement(x));
}

function getElementsBySelector(selector){
var i,selid="",selclass="",tag=selector,f,s=[],objlist=[];

if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    f=document.getElementById(fs[1]);
    if(f) return(f.getElementsByTagName(s[1]));
    return(objlist);
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    f=document.getElementById(selid);
    if(f) objlist.push(f);
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className.indexOf(selclass)>=0){
        objlist.push(v[i]);
        }
    }
return(objlist);
}

function Mix(c1,c2){
var i,step1,step2,x,y,r=new Array(3);
if(c1.length==4)step1=1;
else step1=2;
if(c2.length==4) step2=1;
else step2=2;
for(i=0;i<3;i++){
    x=parseInt(c1.substr(1+step1*i,step1),16);
    if(step1==1) x=16*x+x;
    y=parseInt(c2.substr(1+step2*i,step2),16);
    if(step2==1) y=16*y+y;
    r[i]=Math.floor((x*50+y*50)/100);
    }
return("#"+r[0].toString(16)+r[1].toString(16)+r[2].toString(16));
} 
/*Round Corner Scripts Ends Here*/
                   
   //***************************** END ************************************************************