// JavaScript Document

// Toggle manager details
function mngDis(elementValue, divId){
	if(document.getElementById(divId)){
		if(elementValue == "Manager"){
			document.getElementById(divId).style.display = "block";
		} else {
			document.getElementById(divId).style.display = "none";
			}
		}		
	}

// Populating sub links div for respecive page
function popSubLinks(category, resDivId){
	
	var linkArray = new Array();
	linkArray[0] = new Array('home','Infoflow', 'index.htm', "337px");
	linkArray[1] = new Array('home','About Us', 'aboutus.htm', "337px");
	linkArray[2] = new Array('home','Services', 'services.htm', "337px");
	linkArray[3] = new Array('home','Free Trial', 'freeTrial.htm', "337px");
	linkArray[4] = new Array('iPhone','iTranscribe', 'iTranscribe.htm', "459px");
	linkArray[5] = new Array('iPhone','Register', 'registration.asp', "459px");
	linkArray[6] = new Array('contactus','', '', "598px");
	
	if(document.getElementById(resDivId)){
		document.getElementById(resDivId).innerHTML = "";
		for(var i=0; i<linkArray.length; i++ ){
			if(linkArray[i][0] == category){				
				if(location.href.indexOf(linkArray[i][2]) != -1){
					document.getElementById(resDivId).innerHTML += linkArray[i][1] + "&nbsp;&nbsp;&nbsp;&nbsp;";
					} else {
						document.getElementById(resDivId).innerHTML += "<a href=\"" + linkArray[i][2] + "\" target=\"_self\">" + linkArray[i][1] + "</a>&nbsp;&nbsp;&nbsp;&nbsp;";
						}				
				document.getElementById('subLinkWrapper').style.left = linkArray[i][3];				
				}
				
			}
		}
		
	if(category == "home"){
		if(document.getElementById("topLkSlider")){
			document.getElementById("topLkSlider").style.display="block";
			document.getElementById("topLkSlider").style.left="0px";
			document.getElementById("sliderImg").src="images/assets/homeHtBg.gif";			
			}
		// Change Button img to white
		if(document.getElementById("home_But")){
			document.getElementById("home_But").src="images/assets/homeBut_W.gif";
			}
		} if(category == "iPhone"){
			if(document.getElementById("topLkSlider")){
				document.getElementById("topLkSlider").style.display="block";
				document.getElementById("topLkSlider").style.left="122px";
				document.getElementById("sliderImg").src="images/assets/homeHtBg.gif";			
				}
			// Change Button img to white
			if(document.getElementById("iPhone_But")){
				document.getElementById("iPhone_But").src="images/assets/iPhoneBut_W.gif";
				}
		} if(category == "contactus"){
			if(document.getElementById("topLkSlider")){
				document.getElementById("topLkSlider").style.display="block";
				document.getElementById("topLkSlider").style.left="460px";
				document.getElementById("sliderImg").src="images/assets/homeHtBg.gif";			
				}
			// Change Button img to white
			if(document.getElementById("contactUs_But")){
				document.getElementById("contactUs_But").src="images/assets/contactUsBut_W.gif";
				}
		} 
		
	}

var emailReg=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
var digitReg=/^\d+$/;

//Email validation
function validateEmail(emailToValidate, errLabel, elementId){
	document.getElementById(errLabel).innerHTML="";
	if(emailToValidate.length>0){
		if(!emailReg.test(emailToValidate)){
			document.getElementById(errLabel).innerHTML="Invalid email!";
			document.getElementById(elementId).value="";
			document.getElementById(elementId).focus();
			}
		}
	
	}


//Mandatory fields validation
function validateMandatory(mandatoryFields, errorLabel){
	if(document.getElementById(errorLabel)){
		document.getElementById(errorLabel).innerHTML="";
		}
	
	var mndFields = mandatoryFields.split(",");	
	for(var i=0;i<=mndFields.length-1;i++){	
		if(trimAll(document.getElementById(mndFields[i]).value).length==0){
			if(errorLabel == "undefined"){
				alert("All fields marked * are mandatory!");
				} else if(document.getElementById(errorLabel)){
					document.getElementById(errorLabel).innerHTML="All fields marked * are mandatory!";	
					}
			return false;
			break;
			}
		}
				
		return true;
	}

//Trim white spaces
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;
}

// Min Password length
function pwdLength(fieldToValidate, errorDiv){
	document.getElementById(errorDiv).innerHTML = "";
	if(trimAll(document.getElementById(fieldToValidate).value).length < 4){
		document.getElementById(errorDiv).innerHTML = "Password min. 4 characters!";
		document.getElementById(fieldToValidate).value = "";
		}
	}

//Match confirm password
function pwdMat(fieldToValidate,fieldToCompare,errorDiv){
	document.getElementById(errorDiv).innerHTML="";
	if(document.getElementById(fieldToCompare).value!=document.getElementById(fieldToValidate).value){
		document.getElementById(fieldToValidate).value="";
		document.getElementById(errorDiv).innerHTML = "Password & confirm password does not match!";
		}
	}