/****************************************************************************
File Name: from_validation.js
Purpose: This file is used for form validation.
Task Owner:   
Developed By: Veeneet
Developed On: 09-july-2007
Task Code:
Qr By:
Task Lead: vinay
**************************************************************************/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;
//function to check integer value
function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//function to check special character in string
function checkSpecialChars(parValue){
     var receivedValue = parValue;
     var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~`";     
     for (var i = 0; i < receivedValue.length; i++) {
        if (iChars.indexOf(receivedValue.charAt(i)) != -1) {
            return -1;              	
      	}
    }
    return 1;    
}
//function to remove spaces from front and end of string
function trimAll(sString){

    while (sString.substring(0,1) == ' '){
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' '){
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

// Function for email check.
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
		 
		 if (str.substring(ldot+1)==''){
		    return false
		 }

 		 return true					
	}
//function to clear textbox
function clearValue(fistvalue,secondvalue,color_id){
    if(window.confirm("Do you want to clear record?")){
        document.getElementById(fistvalue).value='';
        document.getElementById(secondvalue).value='';
        document.getElementById(color_id).style.backgroundColor='#3369B3';
        if(document.getElementById("hid_left_save_id")){
         document.getElementById("hid_left_save_id").value="1";
        }
    }
}	
//function to add text box	
/*function addElement(myDiv,theValue,orgtitle,orgtitleid,orgurl,orgurlid,posted_val_title,posted_val_url) {
       var ni = document.getElementById(myDiv);
       var numi = document.getElementById(theValue);
       var num = (document.getElementById(theValue).value -1)+ 2;
       numi.value = num;
       var newdiv = document.createElement('div');
       var divIdName = myDiv+num;
       newdiv.setAttribute('id',divIdName);
       var html1 = '';
       if(orgurl != ''){
           html1 = '<table width="100%"  border="0" cellspacing="2" cellpadding="0" align="left"><tr>';
           //html1 += '<td width="2%" bgcolor="#3369B3" valign="top" id="add_name_id'+num+'">&nbsp;</td>';
           html1 += '<td width="2%" valign="top">';
           html1 += '<table  border="0" cellspacing="0" cellpadding="0">';
           html1 += '<tr><td width="7" valign="top" bgcolor="#3369B3" id="add_name_id'+num+'">&nbsp;</td></tr>';
           html1 += '</table>';
           html1 += '</td>';
           html1 += '<td width="7%" valign="top" class="main_text">Title:</td>';
           html1 += '<td width="25%" valign="top"><input type="text" name="'+orgtitle+num+'" id="'+orgtitleid+num+'" value="" size="25" maxlength="100" onKeyUp="changeLinkTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\',\''+orgurlid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '<td width="2%" valign="top">&nbsp;</td>';
           html1 += '<td width="7%" valign="top" class="main_text">URL:</td>';
           html1 += '<td width="25%" valign="top"><input type="text" name="'+orgurl+num+'" id="'+orgurlid+num+'" value="" size="25" maxlength="100" onblur="return checkUrlWWW(this.value);" onKeyUp="changeLinkTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\',\''+orgurlid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '<td width="1%" valign="top">&nbsp;</td>';
           html1 += '<td width="31%" valign="top"><a href="javascript:clearValue(\''+orgtitleid+num+'\',\''+orgurlid+num+'\',\'add_name_id'+num+'\');"><img src="images/cross.jpg" width="18" height="19" border=0></a></td>';
           html1 += '</tr></table>';
       }
       else if(orgurl == ''){
           html1 = '<table width="100%"  border="0" cellspacing="2" cellpadding="0"><tr>';
           html1 += '<td width="7%" valign="top">';
           html1 += '<table  border="0" cellspacing="0" cellpadding="0">';
           html1 += '<tr><td width="7" valign="top" bgcolor="#3369B3" id="add_name_id'+num+'">&nbsp;</td></tr>';
           html1 += '</table>';
           html1 += '</td>';
           html1 += '<td width="16%" class="main_text" valign="top">Email:</td>';
           html1 += '<td width="77%" valign="top"><input type="text" name="'+orgtitle+num+'" id="'+orgtitleid+num+'" value="'+posted_val_title+'" size="25" maxlength="100" onKeyUp="changeSingleTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '</tr></table>';
       }
       newdiv.innerHTML = html1;
            
       ni.appendChild(newdiv);
}*/


//function to add text box	
function addElement(myDiv,theValue,orgtitle,orgtitleid,orgurl,orgurlid,posted_val_title,posted_val_url) {
       
       var ni = document.getElementById(myDiv);
       var numi = document.getElementById(theValue);
       
       var num = (document.getElementById(theValue).value -1)+ 2;
       if(document.getElementById(theValue+"_post")){
       var num_post = document.getElementById(theValue+"_post");
       num_post.value = num;
       }
       //alert(document.getElementById(theValue+"_post").value);
       numi.value = num;       
       var newdiv = document.createElement('div');
       var divIdName = myDiv+num;
      // var div_name = "tmp"+divIdName;
       //newdiv.setAttribute("name", div_name);
       newdiv.setAttribute('id',divIdName);
       var html1 = '';
       if(orgurl != ''){
           html1 = '<table width="100%"  border="0" cellspacing="2" cellpadding="0"><tr>';
           //html1 += '<td width="2%" bgcolor="#3369B3" valign="top" id="add_name_id'+num+'">&nbsp;</td>';
           html1 += '<td width="2%" valign="top">';
           html1 += '<table  border="0" cellspacing="0" cellpadding="0">';
           html1 += '<tr><td width="7" valign="top" bgcolor="#3369B3" id="add_name_id'+num+'">&nbsp;</td></tr>';
           html1 += '</table>';
           html1 += '</td>';
           html1 += '<td width="7%" valign="top" class="main_text">Title:</td>';
           html1 += '<td width="25%" valign="top"><input type="text" name="'+orgtitle+num+'" id="'+orgtitleid+num+'" value="" size="25" maxlength="100" onKeyUp="changeLinkTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\',\''+orgurlid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '<td width="2%" valign="top">&nbsp;</td>';
           html1 += '<td width="7%" valign="top" class="main_text">URL:</td>';
           html1 += '<td width="25%" valign="top"><input type="text" name="'+orgurl+num+'" id="'+orgurlid+num+'" value="" size="25" maxlength="100" onblur="return checkUrlWWW(this.value);" onKeyUp="changeLinkTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\',\''+orgurlid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '<td width="1%" valign="top">&nbsp;</td>';
           html1 += '<td width="31%" valign="top"><a href="javascript:clearValue(\''+orgtitleid+num+'\',\''+orgurlid+num+'\',\'add_name_id'+num+'\');"><img src="images/cross.jpg" width="18" height="19" border="0"></a></td>';
           html1 += '</tr></table>';
       }
       else if(orgurl == ''){
           html1 = '<table width="100%"  border="0" cellspacing="2" cellpadding="0"><tr>';
           html1 += '<td width="7%" valign="top">';
           html1 += '<table  border="0" cellspacing="0" cellpadding="0">';
           html1 += '<tr><td width="7" valign="top" bgcolor="#3369B3" id="add_name_id'+num+'">&nbsp;</td></tr>';
           html1 += '</table>';
           html1 += '</td>';
           html1 += '<td width="16%" class="main_text" valign="top">Email:</td>';
           html1 += '<td width="77%" valign="top"><input type="text" name="'+orgtitle+num+'" id="'+orgtitleid+num+'" value="'+posted_val_title+'" size="25" maxlength="100" onKeyUp="changeSingleTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '</tr></table>';
       }
       
       newdiv.innerHTML = html1;
            
       ni.appendChild(newdiv);
}
function addElementPostValue(myDiv1,theValue1,postValue1,orgtitle1,orgtitleid1,orgurl1,orgurlid1,posted_val_title1,posted_val_url1) {
       var myDiv = '';
       var theValue = '';
       var postValue = '';
       var orgtitle = '';
       var orgtitleid = '';
       var orgurl = '';
       var orgurlid = '';
       var posted_val_title = '';
       var posted_val_url = '';
       
       myDiv = myDiv1;
       theValue = theValue1;
       postValue = postValue1;
       orgtitle = orgtitle1;
       orgtitleid = orgtitleid1;
       orgurl = orgurl1;
       orgurlid = orgurlid1;
       posted_val_title = posted_val_title1;
       posted_val_url = posted_val_url1;
       var color_id = "add_name_id";
       if(myDiv == "dyndivid"){
       color_id = "request_name_id";
       }
       var ni = document.getElementById(myDiv);
       var num = postValue;
        var numi = document.getElementById(theValue);
        numi.value = num;
       var newdiv = document.createElement('div');
       var divIdName = myDiv+num;
      // var div_name = "tmp"+divIdName;
       //newdiv.setAttribute("name", div_name);
       newdiv.setAttribute('id',divIdName);
       var html1 = '';
       if(orgurl != ''){
           html1 = '<table width="100%"  border="0" cellspacing="2" cellpadding="0" align="left"><tr>';
           //html1 += '<td width="2%" bgcolor="#3369B3" valign="top" id="add_name_id'+num+'">&nbsp;</td>';
           html1 += '<td width="2%" valign="top">';
           html1 += '<table  border="0" cellspacing="0" cellpadding="0">';
           html1 += '<tr><td width="7" valign="top" bgcolor="#3369B3" id="add_name_id'+num+'">&nbsp;</td></tr>';
           html1 += '</table>';
           html1 += '</td>';
           html1 += '<td width="7%" valign="top" class="main_text">Title:</td>';
           html1 += '<td width="25%" valign="top"><input type="text" name="'+orgtitle+num+'" id="'+orgtitleid+num+'" value="" size="25" maxlength="100" onKeyUp="changeLinkTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\',\''+orgurlid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '<td width="2%" valign="top">&nbsp;</td>';
           html1 += '<td width="7%" valign="top" class="main_text">URL:</td>';
           html1 += '<td width="25%" valign="top"><input type="text" name="'+orgurl+num+'" id="'+orgurlid+num+'" value="" size="25" maxlength="100" onblur="return checkUrlWWW(this.value);" onKeyUp="changeLinkTdBackColor(\'add_name_id'+num+'\',\''+orgtitleid+num+'\',\''+orgurlid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '<td width="1%" valign="top">&nbsp;</td>';
           html1 += '<td width="31%" valign="top"><a href="javascript:clearValue(\''+orgtitleid+num+'\',\''+orgurlid+num+'\',\'add_name_id'+num+'\');"><img src="images/cross.jpg" width="18" height="19" border="0"></a></td>';
           html1 += '</tr></table>';
       }
       else if(orgurl == ''){
           
           html1 = '<table width="100%"  border="0" cellspacing="2" cellpadding="0"><tr>';
           html1 += '<td width="7%" valign="top">';
           html1 += '<table  border="0" cellspacing="0" cellpadding="0">';
           html1 += '<tr><td width="7" valign="top" bgcolor="#3369B3" id="'+color_id+num+'">&nbsp;</td></tr>';
           html1 += '</table>';
           html1 += '</td>';
           html1 += '<td width="16%" class="main_text" valign="top">Email:</td>';
           html1 += '<td width="77%" valign="top"><input type="text" name="'+orgtitle+num+'" id="'+orgtitleid+num+'" value="'+posted_val_title+'" size="25" maxlength="100" onKeyUp="changeSingleTdBackColor(\''+color_id+num+'\',\''+orgtitleid+num+'\');" onKeyPress="sethiddenvalueNew(event);"></td>';
           html1 += '</tr></table>';
       
       }
       
       newdiv.innerHTML = html1;
            
       ni.appendChild(newdiv);
}

//function to validate url
function check_url(urlval) {
     var theurl=urlval;
     if(theurl != ''){
     //var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     var tomatch= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if (tomatch.test(theurl))
     {
         return true;
     }
     else
     {
         //window.alert("URL format is not correct, please enter correct format.");
         return false; 
     }
     }
}
//function to check url with change return statement
function checkUrl(urlval) {
     var theurl=urlval;
     if(theurl != ''){
     //var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     var tomatch= /[A-Za-z0-9\.-]{2,}\.[A-Za-z]{2}/
     if (tomatch.test(theurl))
     {
         return true;
     }
     else
     {
         //window.alert("URL format is not correct, please enter correct format.");
         return false; 
     }
     }
}
//function to match http in url
function matchHttpInUrl(urlval){
     
     var theurl=urlval.substring(0,4).toLowerCase();
     if(theurl != ''){
     
     if (theurl == 'http')
     {
         return true;
     }
     else
     {
         //window.alert("URL format is not correct, please enter correct format.");
         return false; 
     }
     }
} 
//function to check url with www attached statement
function checkUrlWWW(urlval) {
     var theurl=urlval;
     if(theurl != ''){
    // var tomatch= /www\.[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     //var tomatch= /[W-Ww-w]{3}\.[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     if(urlval.indexOf ('w', 0) != -1){
     var tomatch= /[W-Ww-w]{3}\.[A-Za-z0-9\.-]{2,}\.[A-Za-z]{2}/
     }
     else{
     var tomatch= /[A-Za-z0-9\.-]{2,}\.[A-Za-z]{2}/
     }
     
     if (tomatch.test(theurl))
     {
         return true;
     }
     else
     {
         //window.alert("URL format is not correct, please enter correct format.");
         return false; 
     }
     }
}

function easyUrlValidation(urlval){   
    if(urlval!=""){
        if(urlval.indexOf ('w', 0) != -1){
            if (urlval.indexOf ('www', 0) == -1 || urlval.length < 10){
                return false;
            }
            else if(urlval.indexOf ('.com', 0) == -1 || urlval.length < 10){
                return false;
            }
        }
        else if(urlval.indexOf ('.com', 0) == -1 || urlval.length < 10){
            return false;
        }
   }
}
//function to open pdf
function openPDF(filename){
	
	window.open(filename);
}
//function to open pdf
function openPopup(filename,formname,wid,heit,resize_value,scroll_bar){
	if(resize_value == ''){
  resize_value = 0;
  }
  if(scroll_bar == ''){
  scroll_bar = 0;
  }
	window.open(filename,formname,'resizable='+resize_value+',scrollbars='+scroll_bar+', width='+wid+',height='+heit);
}
function CheckInteger(s)
    {   var i;
    
        for (i = 0; i < s.length; i++)
        {   
            // Check that current character is number.
            var c = s.charAt(i);
            if ((c < "0") || (c > "9")) {
              if(i==3 && c != '-'){
               if((c < "0") || (c > "9")) return false;
              }
              
              
            }
        }
        // All characters are numbers.
        return true;
    }
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){

s=stripCharsInBag(strPhone,validWorldPhoneChars);
//alert(s);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
var n;
var p;
var p1;
function ValidatePhone(){
p=trimAll(p1.value);
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	if(n=='phone'){
	document.manage_profile.phone.value="";
	document.manage_profile.phone.value=pp;
	}
	if(n=='fax'){
	document.manage_profile.fax.value="";
	document.manage_profile.fax.value=pp;
	}
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		if(n=='phone'){
	document.manage_profile.phone.value="";
	document.manage_profile.phone.value=pp;
	}
	if(n=='fax'){
	document.manage_profile.fax.value="";
	document.manage_profile.fax.value=pp;
	}
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	if(n=='phone'){
	document.manage_profile.phone.value="";
	
	}
	if(n=='fax'){
	document.manage_profile.fax.value="";
	
	}
	pp="("+p13+")"+p14+p15;
	if(n=='phone'){
	
	document.manage_profile.phone.value=pp;
	}
  if(n=='fax'){

	document.manage_profile.fax.value=pp;
	}
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	if(n=='phone'){
	document.manage_profile.phone.value="";
	document.manage_profile.phone.value=pp;
	}
	if(n=='fax'){
	document.manage_profile.fax.value="";
	document.manage_profile.fax.value=pp;
	}
	//obj1.value="";
	//obj1.value=pp;
	}
}
//}
setTimeout(ValidatePhone,100)
}
function getIt(m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
}
function testphone(obj1){
p=trimAll(obj1.value);
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}
function confirm_del(){
  return window.confirm("Do you want to delete?");
}    
/*var dot="."
        paramlength = document.bfeed.textbbrd.value.length;
        var ldot=param.indexOf(dot);
        if (param.substring(ldot+1)==''){
		    alert("enter validfg url");
        document.bfeed.textbbrd.focus();
        return false;     
		    }else if (param.substring(ldot+3)=='xml'){
		    alert("doneff");
		    }
        else if(param.indexOf(dot) == '4'){
        alert("donefdfdgff");
        }else{
        alert("enter valid url");
        document.bfeed.textbbrd.focus();
        return false;     
        }*/
function changeTdBackColor(td_id,contvalue){
var cont_value = document.getElementById(contvalue).value;
if(trimAll(cont_value) == ''){
document.getElementById(td_id).style.backgroundColor='#FF0000';
}
else{

if(contvalue == 'phone_id'){
    if (checkInternationalPhone(cont_value)==false){
     document.getElementById(td_id).style.backgroundColor='#FF0000';
   }
   else{
   document.getElementById(td_id).style.backgroundColor='#009900';
   }
}
else if(contvalue == 'email_id'){
   if(echeck(cont_value) == false){
       document.getElementById(td_id).style.backgroundColor='#FF0000';
   }
   else{
       document.getElementById(td_id).style.backgroundColor='#009900';
   }

}
else{
document.getElementById(td_id).style.backgroundColor='#009900';
}
}
}

function checkpasscolor(){
var choose_pass = document.getElementById("choose_pass_id").value;
var re_enter_pass = document.getElementById("re_enter_pass_id").value;
if(trimAll(choose_pass) == ''){
document.getElementById("choose_pass_id1").style.backgroundColor='#FF0000';
document.getElementById("re_enter_pass_id1").style.backgroundColor='#FF0000';
}
else if(trimAll(re_enter_pass) == ''){//check re enter password is blank or not
document.getElementById("re_enter_pass_id1").style.backgroundColor='#FF0000';
document.getElementById("choose_pass_id1").style.backgroundColor='#FF0000';
}
else if(trimAll(choose_pass) != '' && choose_pass.length < 6){
document.getElementById("choose_pass_id1").style.backgroundColor='#FF0000';
document.getElementById("re_enter_pass_id1").style.backgroundColor='#FF0000';
}
else if(trimAll(re_enter_pass) != '' && re_enter_pass.length < 6){
document.getElementById("re_enter_pass_id1").style.backgroundColor='#FF0000';
document.getElementById("choose_pass_id1").style.backgroundColor='#FF0000';
}
else if(trimAll(choose_pass) != trimAll(re_enter_pass)){
document.getElementById("re_enter_pass_id1").style.backgroundColor='#FF0000';
document.getElementById("choose_pass_id1").style.backgroundColor='#FF0000';
}
else{
document.getElementById("choose_pass_id1").style.backgroundColor='#009900';
document.getElementById("re_enter_pass_id1").style.backgroundColor='#009900';
}
}

function changeTdoptBackColor(td_id,contvalue){
var cont_value = document.getElementById(contvalue).value;
if(trimAll(cont_value) == ''){
document.getElementById(td_id).style.backgroundColor='#3369B3';
}
else{
if(contvalue == 'fax_id'){
    if (checkInternationalPhone(cont_value)==false){
     document.getElementById(td_id).style.backgroundColor='#3369B3';
   }
   else{
   document.getElementById(td_id).style.backgroundColor='#009900';
   }
}
else{
document.getElementById(td_id).style.backgroundColor='#009900';
}
}
}

function changeTdcomboBackColor(td_id,contvalue){
var cont_value = document.getElementById(contvalue).value;
if(trimAll(cont_value) == '0'){
document.getElementById(td_id).style.backgroundColor='#FF0000';
}
else{


document.getElementById(td_id).style.backgroundColor='#009900';

}
}

function changeTdcombooptBackColor(td_id,contvalue){
var cont_value = document.getElementById(contvalue).value;
if(trimAll(cont_value) == '0'){
document.getElementById(td_id).style.backgroundColor='#3369B3';
}
else{

document.getElementById(td_id).style.backgroundColor='#009900';

}
}
function link_website(web_value){
//alert(web_value);
var web_link = "<a href=http://"+web_value+" target='_BLANK'>http://"+web_value+"</a>";
//website_link.innerHTML = "TEST";
document.getElementById("website_link1").innerHTML = web_link;
}
function fillwebsite(web_id){
var web_value = document.getElementById(web_id).value;
var web_link = "<a href=http://"+web_value+" target='_BLANK'>http://"+web_value+"</a>";
//website_link.innerHTML = web_link;
document.getElementById("website_link1").innerHTML = web_link;
}
//function to change back color of td in case of edit link
function changeLinkTdBackColor(td_id,contvalue,contvalue1){

var cont_value  = document.getElementById(contvalue).value;
var cont_value1 = document.getElementById(contvalue1).value;
if(trimAll(cont_value) == '' || trimAll(cont_value1) == ''){
document.getElementById(td_id).style.backgroundColor='#3369B3';
}
else{
if(trimAll(cont_value1) != ''){
    if(checkUrlWWW(cont_value1) == false){
      
        document.getElementById(td_id).style.backgroundColor='#3369B3';
    }
    else{
        document.getElementById(td_id).style.backgroundColor='#009900';
    }
}
else{
    document.getElementById(td_id).style.backgroundColor='#009900';
}
}
}

//function to change back color of td in case of edit link
function changeSingleTdBackColor(td_id,contvalue){

var cont_value  = document.getElementById(contvalue).value;

if(trimAll(cont_value) == ''){
document.getElementById(td_id).style.backgroundColor='#3369B3';
}
else{
if(trimAll(cont_value) != ''){
    if(echeck(cont_value) == false){
    
        document.getElementById(td_id).style.backgroundColor='#3369B3';
    }
    else{
        document.getElementById(td_id).style.backgroundColor='#009900';
    }
}
else{
    document.getElementById(td_id).style.backgroundColor='#009900';
}
}
}
function checkPhoneFormat1(phoneValue){
s=trimAll(phoneValue);
if(s.charAt(0)!="("){
    return false;
}
while (s.substring(1,4) == ' '){
    return false;
}
while(!isInteger(s.substring(1,4))){
    return false;
}
if(s.charAt(4)!=")"){
    return false;
}
while (s.substring(5,8) == ' '){
    return false;
}
while(!isInteger(s.substring(5,8))){
    return false;
}    
if(s.charAt(8)!="-"){
		return false;
}
while (s.substring(9) == ' '){
    return false;
}
while(!isInteger(s.substring(9))){
    return false;
}
return true;        
//alert(s);
//return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function checkPhoneFormat(phoneValue){
if(!checkPhoneFormat1(phoneValue.value)){
if(phoneValue.name=="phone"){
alert("Enter Phone Number in format (949)450-9244.");
}
else if(phoneValue.name=="fax"){
alert("Enter Fax in format (949)450-9244.");
}

return false;
}
}

function sethiddenvalue(){
if(document.getElementById("hid_left_save_id")){
document.getElementById("hid_left_save_id").value="1";
}
}

function sethiddenvalueNew(e){
//var iCode = window.event.keyCode;
//alert(iCode);
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
  {
  keynum = e.keyCode;
  }
else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
  //alert(keynum);

if(document.getElementById("hid_left_save_id")){
document.getElementById("hid_left_save_id").value="1";
}
}

//function to change back color in case of company info
function changeCompanyBackColor(){

var industries_id = document.getElementById("industries_id").value;
var comp_org_id = document.getElementById("comp_org_id").value;
var comp_title_id = document.getElementById("comp_title_id").value;
var comp_div_id = document.getElementById("comp_div_id").value;
if(trimAll(industries_id) == '0' || trimAll(comp_org_id) == '' || trimAll(comp_title_id) == '' || trimAll(comp_div_id) == '0'){
document.getElementById("comp_org_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("comp_org_id1").style.backgroundColor='#009900';
}
}
function changeCompanyBackColor_reg(){
var industries_id = document.getElementById("industries_id").value;
var comp_org_id = document.getElementById("company_id").value;
var comp_title_id = document.getElementById("title_id").value;
var comp_div_id = document.getElementById("comp_div_id").value;
if(trimAll(industries_id) == '0' || trimAll(comp_org_id) == '' || trimAll(comp_title_id) == '' || trimAll(comp_div_id) == '0'){
document.getElementById("comp_org_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("comp_org_id1").style.backgroundColor='#009900';
}
}

function newIndustry(newind,replace_div,field_type){
if(newind == 'new'){

var html = '';
if(field_type == 'division'){
html = "<input type='text' name='create_new_div' id='create_new_div_id' class='regular_text' value='' maxlength='100' size='25' onClick='sethiddenvalueNew(event);'>";
}else{
html = "<input type='text' name='create_new_ind' id='create_new_ind_id' class='regular_text' value='' maxlength='100' size='25' onClick='sethiddenvalueNew(event);'>";
}

document.getElementById(replace_div).innerHTML = html;
}
else if(newind != 'new'){
document.getElementById(replace_div).innerHTML = '';
}
}

function newindBackColor(change_val,div_id,page_type,field_type){
if(page_type == 'manage'){
    changeCompanyBackColor();
}
else if(page_type == 'reg'){
    changeCompanyBackColor_reg();
}
newIndustry(change_val,div_id,field_type);
}
function changeTdBackColorPhone(change_type){
if(change_type == 'phone_id1'){
var phone_first         = document.getElementById('phone_first_id').value;
var phone_second         = document.getElementById('phone_second_id').value;
var phone_third         = document.getElementById('phone_third_id').value;

if(trimAll(phone_first) == '' || trimAll(phone_second) == '' || trimAll(phone_third) == ''){
document.getElementById("phone_id1").style.backgroundColor='#FF0000';
}
else if(trimAll(phone_first) != '' && trimAll(phone_second) != '' && trimAll(phone_third) != ''){
if ((isInteger(phone_first)==false) || (isInteger(phone_second)==false) || (isInteger(phone_third)==false)){
document.getElementById("phone_id1").style.backgroundColor='#FF0000';
}
else if(phone_first.length<3){
document.getElementById("phone_id1").style.backgroundColor='#FF0000';
}
else if(phone_second.length<3){
document.getElementById("phone_id1").style.backgroundColor='#FF0000';
}
else if(phone_third.length<4){
document.getElementById("phone_id1").style.backgroundColor='#FF0000';
}
else{
document.getElementById("phone_id1").style.backgroundColor='#009900';
}
}
}
if(change_type == 'fax_id1'){
var fax_first     = trimAll(document.getElementById('fax_first_id').value);
var fax_second     = trimAll(document.getElementById('fax_second_id').value);
var fax_third     = trimAll(document.getElementById('fax_third_id').value);
if(trimAll(fax_first) == '' || trimAll(fax_second) == '' || trimAll(fax_third) == ''){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(trimAll(fax_first) != '' && trimAll(fax_second) != '' && trimAll(fax_third) != ''){
if ((isInteger(fax_first)==false) || (isInteger(fax_second)==false) || (isInteger(fax_third)==false)){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(fax_first.length<3){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(fax_second.length<3){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(fax_third.length<4){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("fax_id1").style.backgroundColor='#009900';
}
}
}
if(change_type == 'mobile_id1'){
var mobile_first     = trimAll(document.getElementById('mobile_first_id').value);
var mobile_second     = trimAll(document.getElementById('mobile_second_id').value);
var mobile_third     = trimAll(document.getElementById('mobile_third_id').value);
if(trimAll(mobile_first) == '' || trimAll(mobile_second) == '' || trimAll(mobile_third) == ''){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(trimAll(mobile_first) != '' && trimAll(mobile_second) != '' && trimAll(mobile_third) != ''){
if ((isInteger(mobile_first)==false) || (isInteger(mobile_second)==false) || (isInteger(mobile_third)==false)){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(mobile_first.length<3){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(mobile_second.length<3){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(mobile_third.length<4){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("mobile_id1").style.backgroundColor='#009900';
}
}
}
}

function changeTdBackColorPhoneNew(change_type){
if(change_type == 'phone_id1'){
var phone_first         = document.getElementById('phone_first_id').value;
var phone_second         = document.getElementById('phone_second_id').value;
var phone_third         = document.getElementById('phone_third_id').value;

if(trimAll(phone_first) == '' || trimAll(phone_second) == '' || trimAll(phone_third) == ''){
document.getElementById("phone_id1").style.backgroundColor='#3369B3';
}
else if(trimAll(phone_first) != '' && trimAll(phone_second) != '' && trimAll(phone_third) != ''){
if ((isInteger(phone_first)==false) || (isInteger(phone_second)==false) || (isInteger(phone_third)==false)){
document.getElementById("phone_id1").style.backgroundColor='#3369B3';
}
else if(phone_first.length<3){
document.getElementById("phone_id1").style.backgroundColor='#3369B3';
}
else if(phone_second.length<3){
document.getElementById("phone_id1").style.backgroundColor='#3369B3';
}
else if(phone_third.length<4){
document.getElementById("phone_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("phone_id1").style.backgroundColor='#009900';
}
}
}
if(change_type == 'fax_id1'){
var fax_first     = trimAll(document.getElementById('fax_first_id').value);
var fax_second     = trimAll(document.getElementById('fax_second_id').value);
var fax_third     = trimAll(document.getElementById('fax_third_id').value);
if(trimAll(fax_first) == '' || trimAll(fax_second) == '' || trimAll(fax_third) == ''){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(trimAll(fax_first) != '' && trimAll(fax_second) != '' && trimAll(fax_third) != ''){
if ((isInteger(fax_first)==false) || (isInteger(fax_second)==false) || (isInteger(fax_third)==false)){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(fax_first.length<3){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(fax_second.length<3){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else if(fax_third.length<4){
document.getElementById("fax_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("fax_id1").style.backgroundColor='#009900';
}
}
}
if(change_type == 'mobile_id1'){
var mobile_first     = trimAll(document.getElementById('mobile_first_id').value);
var mobile_second     = trimAll(document.getElementById('mobile_second_id').value);
var mobile_third     = trimAll(document.getElementById('mobile_third_id').value);
if(trimAll(mobile_first) == '' || trimAll(mobile_second) == '' || trimAll(mobile_third) == ''){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(trimAll(mobile_first) != '' && trimAll(mobile_second) != '' && trimAll(mobile_third) != ''){
if ((isInteger(mobile_first)==false) || (isInteger(mobile_second)==false) || (isInteger(mobile_third)==false)){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(mobile_first.length<3){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(mobile_second.length<3){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else if(mobile_third.length<4){
document.getElementById("mobile_id1").style.backgroundColor='#3369B3';
}
else{
document.getElementById("mobile_id1").style.backgroundColor='#009900';
}
}
}
}

function changeFocus(change_type,type_name){
var count = 0;
if(change_type == 'phone_id1'){
if(type_name == 'phone_first_id'){
var phone_first         = document.getElementById('phone_first_id').value;
if(phone_first.length < 3){
document.getElementById('phone_first_id').focus();
}
else if(phone_first.length >= 3){
//document.getElementById('phone_first_id').focus() = false;
document.getElementById('phone_second_id').focus();
count = 1;
}
}
if(type_name == 'phone_second_id'){
var phone_second         = document.getElementById('phone_second_id').value;
if(phone_second.length < 3){
document.getElementById('phone_second_id').focus();
}
else if(phone_second.length >= 3){
//document.getElementById('phone_first_id').focus() = false;
document.getElementById('phone_third_id').focus();
count = 1;
}
}
//var phone_second         = document.getElementById('phone_second_id').value;
//var phone_third         = document.getElementById('phone_third_id').value;





}
if(change_type == 'fax_id1'){


//var fax_third     = trimAll(document.getElementById('fax_third_id').value);

if(type_name == 'fax_first_id'){
var fax_first     = trimAll(document.getElementById('fax_first_id').value);
if(fax_first.length < 3){
document.getElementById('fax_first_id').focus();
}
else if(fax_first.length >= 3){
//document.getElementById('phone_first_id').focus() = false;
document.getElementById('fax_second_id').focus();
count = 1;
}
}
if(type_name == 'fax_second_id'){
var fax_second     = trimAll(document.getElementById('fax_second_id').value);
if(fax_second.length < 3){
document.getElementById('fax_second_id').focus();
}
else if(fax_second.length >= 3){
//document.getElementById('phone_first_id').focus() = false;
document.getElementById('fax_third_id').focus();
count = 1;
}
}

}
if(change_type == 'mobile_id1'){


//var mobile_third     = trimAll(document.getElementById('mobile_third_id').value);

if(type_name == 'mobile_first_id'){
var mobile_first     = trimAll(document.getElementById('mobile_first_id').value);
if(mobile_first.length < 3){
document.getElementById('mobile_first_id').focus();
}
else if(mobile_first.length >= 3){
//document.getElementById('phone_first_id').focus() = false;
document.getElementById('mobile_second_id').focus();
count = 1;
}
}
if(type_name == 'mobile_second_id'){
var mobile_second     = trimAll(document.getElementById('mobile_second_id').value);
if(mobile_second.length < 3){
document.getElementById('mobile_second_id').focus();
}
else if(mobile_second.length >= 3){
//document.getElementById('phone_first_id').focus() = false;
document.getElementById('mobile_third_id').focus();
count = 1;
}
}

}
}
