/******************************************
Module name : Js Function file
Parent module : None
Date created : 5th January 2008
Date last modified : 5th January 2008
Author :  Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : The functions_js.js file contains various functions related to the web directory project.
******************************************/	

/******************************************
Function name : showSearchBox
Return type : None
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function is used to show hide the seacch box
User instruction : showSearchBox()
******************************************/
function showSearchBox(varDocumentID, varShow)
{
	if(varShow == 'show')
	{
	 document.getElementById(varDocumentID).style.display = 'block';	
	}
	else
	{
	  document.getElementById(varDocumentID).style.display = 'none';
	}
}

/******************************************
Function name : toggleOption
Return type : None
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will toggle the select all checkbox option.
User instruction : toggleOption(spanChk)
******************************************/
function toggleOption(spanChk)
{
	var xState=spanChk.checked;
	var theBox=spanChk;

	elm=theBox.form.elements;
	
	for(i=0;i<elm.length;i++)
	{
		if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
		{
			if(xState == false)
				elm[i].checked = false;
			else
				elm[i].checked = true;
		}
	}
}

/******************************************
Function name : checkPhone
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the true or false according to phone field validation
User instruction : checkPhone(phone)
******************************************/
function checkPhone(phone)
{
	var phoneRequired = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
	if(!phoneRequired.test(phone))
		return false;
	return true;
}

/******************************************
Function name : getMasterString
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the main string
User instruction : getMasterString()
******************************************/
function getMasterString()
{
	return "Sorry, we can not complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n";
}

/******************************************
Function name : checkError
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the true or false acording to form validation
User instruction : checkError(error)
******************************************/
function checkError(error)
{
	var flag=false;
	var MasterString = getMasterString();
	
	if(error != "")
	{
		MasterString = MasterString + error;
		flag=true;
	}
	
	if(flag == true)
	{
		alert(MasterString);
		return false;
	}
	else
		return true;
}

/******************************************
Function name : askConfirm
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the true or false after asking for confirmation
User instruction : askConfirm(type)
******************************************/
function askConfirm(type)
{	
	var sen = "Are you sure you want to "+type+"?";
	if(confirm(sen))
		return true;
	else
		return false;
}

/******************************************
Function name : validator
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the true or error message after validating checkboxes
User instruction : validator(btnType)
******************************************/
var btnType;
function validator(btnType,formname)
{
	var obj = formname;
	var error="", flagCheck=0;
	
	var len = obj.elements.length; 
	var i=0;
	for(i=0;i<len;i++) 
	{
		if(obj.elements[i].type=='checkbox')
		{
			if(obj.elements[i].checked)
			{
				//if(btnType == 'Delete')
					return askConfirm(btnType);
				//else
					//return true;
			}
			else
				flagCheck = 1;
		}
	}
	
	if(flagCheck == 1)
		error += "\n - Please select at least one record.";
			
	return checkError(error);
}

/******************************************
Function name : validator
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the true or error message after validating checkboxes
User instruction : validator(btnType)
******************************************/
function validateForm() 
{ 
	var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
	j=0;
	//	/^([-a-zA-Z0-9._]+@[-a-zA-Z0-9.]+(\.[-a-zA-Z0-9]+)+)$/;
	var regEmail = /^[0-9a-z]+(([\.\-_])[0-9a-z]+)*@[0-9a-z]+(([\.\-])[0-9a-z-]+)*\.[a-z]{2,4}$/;
	var regBlank = /[^\s]/;
	//var regSpace = /[\s]/;
	var regSpace = /^([a-zA-Z0-9-_!#@]+)$/;
	//var regAlphaNum = /^([a-zA-Z0-9-/_ :;#!@\n\r.,$*&%?^~`=+(){}\[\]\"\'\\]+)$/;
	var regAlphaNum = /^([a-zA-Z0-9_#@!]+)$/;
	 var regDate = /^([0-9_]+-[0-9][0-9]+-[0-9][0-9]+)$/; 
   var regChar = /^([a-zA-Z]+)$/;
	
	//alert (validateForm.arguments[1].name);
	//alert("sss---->"+document.forms[""+args[0]].elements[""+args[0]].value);
	for (i=1; i<(args.length-2); i+=3) 
	{	
		
		mesg=args[i+1];
		test=args[i+2]; 
		val=document.forms[""+args[0]].elements[""+args[i]];
		
		    if (val) 
			{	
				nm=mesg; 
				noVal = val;
				val = val.value;
				
			if(test=='BLNK')
			{
			 if (isNaN(val)) errors+='---> '+nm+' must contain a number.\n';
			 if (val<0) errors+='---> '+nm+' must contain a number.\n';
			 }			
			 else if(test=='CHKURL' && val !="")
				{
					p=val.indexOf('http://');
					s=val.indexOf('.');
			        if (p<0 || p==(val.length-1))
					{
						errors+='---> '+nm+' must be valid URL e.g. http://www.abc.com\n';
		
					}
					else if(s<p || s==(val.length-1))
					{
						errors+='---> '+nm+' must be valid URL e.g. http://www.abc.com\n';
					}

				}
			 else
				{
			if(regBlank.test(val))
			{
				if(test.indexOf('isEqual')!=-1)
				{
					result = trim(val);

				if(result.length==0){
										
				errors += '---> '+nm+' is required.\n'; 
				}else{
					
					equal_obj_val = test.substring(8,test.indexOf(":"));
					mesg_string =test.substring((test.indexOf(":")+1));

					if(val != document.forms[""+args[0]].elements[""+equal_obj_val].value)
					{ 
						errors+='---> '+nm+' and '+mesg_string+' must be same.\n';
					}
				}
				}
				else if(test.indexOf('isPassword')!=-1)
				{ 
					 var min = 6, max = 20;
					 result = trim(val);
					 if(result.length==0)
					 {
					  	errors += '---> '+nm+' is required.\n'; 
					 } 
					 else 
					 {
						  equal_obj_val = test.substring(11,test.indexOf(":"));
						  var valConf =  document.forms[""+args[0]].elements[""+equal_obj_val].value;
						  mesg_string =test.substring((test.indexOf(":")+1));
						  valLength = val.length;
						  valConfLength = valConf.length;
						
						  if(!regSpace.test(val))
						  {
						   	 errors += '---> '+nm+' is not valid.\n';
						  }
						  else if(val != valConf)
						  { 
						   	 errors+='---> '+nm+' and '+mesg_string+' must be same.\n';
						  }
						  else if(!regSpace.test(valConf))
						  {
							 errors += '---> '+mesg_string+' is not valid.\n';
						  }
						  else if(valLength<min || max<valLength)
						  {
							 errors+='---> '+nm+'  between '+min+' and '+max+'.\n';
						  }
						  else if(valConfLength<min || max<valConfLength)
						  {
							 errors+='---> '+nm+'  between '+min+' and '+max+'.\n';
					  	  }
					 }
				}
				else if(test.indexOf('isAlphaNum')!=-1)
				{
				result = trim(val);
				if(result.length==0){
				errors += '---> '+nm+' is required.\n'; 
				}else{
					if(!regAlphaNum.test(val))
					{
						errors += '- '+nm+' is not valid.\n';
						//errors+='- '+nm+': Only Alpha Numeric and "_ , . - ! @ # () {} [] " coma,  single cots and Chars Allowed.\n';
					}
				}
				
				}
				else if(test.indexOf('isSpace')!=-1)
				{
				result = trim(val);
				
				if(result.length==0)
				{
					errors += '---> '+nm+' is required.\n'; 
				}
				else
				{
					if(!regSpace.test(val))
					{
						errors+='---> '+nm+': Only Alpha Numeric and "_ - ! @ # " Allowed.\n';
						//errors += '- '+nm+' is not valid.\n';
					}
				}
				}
				else if (test.indexOf('isDate')!=-1) 
				{ 
					p=val.indexOf('-');
			       // alert(test.indexOf('isDate'));
			       	var sliptdate	= val.split("-");
					
					/*******************Added by rupesh Date is not before current date and month*********************/
					var today=new Date(),TY=today.getFullYear(),TM=today.getMonth(),TD=today.getDate(),TH=today.getHours();
					TM+=1;			
					if(TM<=9) 
					{	
						TM='0'+TM;
					}
					if(TD<=9)
					{
						TD='0'+TD;
					}
					/*******************Added by rupesh*********************/
					
					var sY=sliptdate[0];
					var sM=sliptdate[1];
					var sD=sliptdate[2];
					
					/*******************Added by rupesh*********************/
					//alert(TM);
					if(sY<TY ) {
						
						errors+='---> '+nm+' should be greater than current date.\n';
					}
					else if(sM==TM && sD<TD && sY==TY) { 

						errors+='---> '+nm+' should be greater than current date.\n';
						
					}
					else if(sM<TM && sY==TY) { 

						errors+='---> '+nm+' should be greater than current date.\n';
						
					}
					
					/*************************Added by rupesh********************/
					else if (p != 4 || sY.length != 4 || sM.length != 2 || sD.length != 2 )
					{
						errors+='---> '+nm+' must contain valid date YYYY-MM-DD.\n';
					}
					else if(!regDate.test(val))
					{
						errors+='---> '+nm+'  must contain valid date YYYY-MM-DD.\n';
					}
					else if(sM>12 || sD>31 || sY<2006)
					{
						errors+='---> '+nm+'  must contain valid date YYYY-MM-DD.\n';
					}
			     }
				else if (test.indexOf('isEmail')!=-1) 
				{ 
					p=val.indexOf('@');
					s=val.indexOf('.');
			        if (p<1 || p==(val.length-1))
					{
						errors+='---> '+nm+' must contain an e-mail Address.\n';
		
					}
					//else if(s<p || s==(val.length-1))
					else if(!regEmail.test(val))
					{
						errors+='---> '+nm+' must contain a valid e-mail Address.\n';
					}
			     }
				else if (test.indexOf('isUrl')!=-1) 
				{ 
					p=val.indexOf('http://');
					s=val.indexOf('.');
			        if (p<0 || p==(val.length-1))
					{
						errors+='---> '+nm+' must be valid URL e.g. http://www.abc.com\n';
		
					}
					else if(s<p || s==(val.length-1))
					{
						errors+='---> '+nm+' must be valid URL e.g. http://www.abc.com\n';
					}
			     }
				 else if(test.indexOf('isMp3')!=-1)
				 {
					function reverse(val) 
					{	
						var length = val.length;
						var letters = new Array(length);
						var letters2 = new Array(length);
						var backword = "";
						for (i=0; i<=length-1; i++) 
						{
							letters[i] = val.substring(i, i+1);
						}
						f = 0
						for (j=i-1; j>=0; j--) 
						{
							letters2[f] = letters[j];
							f++;
						}
						for (h=0; h<=letters2.length-1; h++) 
						{
							backword +=letters2[h];
						}
					 	return backword;
					}
					var back = reverse(val);
					var ValExt	= back.split(".");
					var ValExt = reverse(ValExt[0]);
					
					if (ValExt == "mp3" || ValExt == "MP3") 
					{
						flag="yes";
					} 
					else 
					{
						flag="no";						
					} 
					if(flag=="no")
					{
						errors+='---> '+nm+' must be (mp3).\n';						
					}
				 
				 }
				 else if (test.indexOf('isChar')!=-1) 
				 { 
					var first_char;
					
					if(val.match(regChar)==null)
					{
					 	errors+='---> '+nm+' must contain a character.\n';
					}
			     }
				 else if(test.indexOf('isCheckbox')!=-1)//Check is check box is not checked generate error
				{	
					var valueCheckbox = noVal.checked;
					if(!valueCheckbox)
					{
						errors+='---> '+' Accept terms and Policy.\n';
					}
				}
	   			 else if (test!='R' || test=='Numbers') 
				 {
				 result = trim(val);
					if(result.length==0){
						
						if(errors.indexOf('Phone') == -1)
					errors += '---> '+nm+' is required.\n'; 
					}
					
				    if (isNaN(val)) 
					{
					 if(errors.indexOf('Phone') == -1)
					 errors+='---> '+nm+' must contain a number.\n';
					}
					else
					{
					if(test=='Numbers' && !isNaN(val))
					{
					var i1;
					var num1=0;
						for (i1 = 0; i1 < val.length; i1++)
						{   
							// Check that current character is number.
							var c = val.charAt(i1);
							if (((c < "0") || (c > "9"))) num1=1;
						}
						if(num1==1)
						{
							if(errors.indexOf('Phone') == -1)
							errors+='---> '+nm+' can only contain numbers.\n';
						}
					}
				 }
					if (test.indexOf('inRange') != -1) 
					{ num = parseFloat(val);
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						
						if (num<min || max<num) 
							if(min==max)
							{
							  if(min==1 && max==1 & num==0)
								{
							errors+='---> '+nm+' should  be more than '+min+'.\n';
							    }
								if(min!=1 && max!=1 && min==max)
								{
							errors+='---> '+nm+' should not be more than '+min+'.\n';
								}
							}				
							
						else
						{
						errors+='---> '+nm+' must contain a number between '+min+' and '+max+'.\n';
						}
					} 
					if (val.indexOf('-') != -1) 
					{ 
						errors='---> '+nm+' must contain a number.\n';
					} 
					if (val.indexOf('+') != -1) 
					{ 
						errors='---> '+nm+' must contain a number.\n';
					}
					
				}else if (test.charAt(0)=='R')
				{
				result = trim(val);
				if(result.length==0){
					
				errors += '---> '+nm+' is required.\n'; 
				}
				} 
			}
			else if (test.charAt(0) == 'R' || test=='Numbers'){
				if(errors.indexOf('Phone') == -1 && test=='Numbers')
				{
				errors += '---> '+nm+' is required.\n'; 
				}
				if (test.charAt(0) == 'R')
				{					
				errors += '---> '+nm+' is required.\n'; 	
				}
			}
		}
			}
		if(errors !="")
		{	if(j<=0)
			{
				focusitem = document.forms[""+args[0]].elements[""+args[i]];
				j++;
			}	
		}
	} 
	
  if (errors)
  {
	var MasterString = getMasterString();
	alert(MasterString+'\n'+errors);
	focusitem.focus();
	return false;
   }
   else
	return true;

  document.MM_returnValue = (errors == '');
}

/******************************************
Function name : stripHTML
Return type : string
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the main string after removing HTML tags
User instruction : stripHTML(str)
******************************************/
function stripHTML(str){
      var re= /<\S[^><]*>(&nbsp;)*/g ;
      return str.replace(re, "") ;
}
/******************************************
Function name : ltrim
Return type : string
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the main string after removing white spaces from the left
User instruction : ltrim(str)
******************************************/
function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
/******************************************
Function name : rtrim
Return type : string
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the main string after removing white spaces from the right
User instruction : rtrim(str)
******************************************/
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
/******************************************
Function name : trim
Return type : string
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the main string after removing white spaces from the right and left of the main string
User instruction : trim(str)
******************************************/
function trim(str) {
	return ltrim(rtrim(str));
}
/******************************************
Function name : isWhitespace
Return type : integer
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : Function will return the index of white space encounter in the string.
User instruction : isWhitespace(charToCheck)
******************************************/
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

/*****************************
Function name : deSelectCheckbox
Return type : none
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : This function is used to deselect check box
User instruction : deSelectCheckbox(formname)
************************************/
function deSelectCheckbox(formname)
{
	document.getElementById('Main').checked = false;
}
/*****************************
Function name :setValidAction
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : This function is used to perform on various Action like delete, activate , deactivate.
User instruction : setValidAction(value, formname,listname)
************************************/
function setValidAction(value, formname,listname)
{
	if(value == 'Delete')
	{
		message = "delete selected "+listname;		
	}
	else
	{
		message = "change status of selected "+listname;
	}
	var flag = validator(message,formname);			
	if(flag)
	{			
		return true;
	}
	else
	{
		document.getElementById('Main').checked = false;
		
		document.forms[0].Main.checked=false;	
		elm=document.forms[0].elements;	
		for(i=0;i<elm.length;i++)
		{
			if(elm[i].type=="checkbox")
			{			
				elm[i].checked = false;
			}
		}
		return false;
	}
}

/*****************************
Function name : checkSearchDate
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to put check on search date.
User instruction : checkSearchDate(obj)
************************************/
function checkSearchDate(obj, option)
{
	var error = "";
	if((obj.frmFromDate.value > obj.frmToDate.value) && obj.frmFromDate.value!='From' && obj.frmToDate.value!='To' )
	{
		error += "\n- 'To' date will be set after 'From' date.";
	}
	
	if(option)
	{
		objDate = new Date();
		arrFromDate = obj.frmFromDate.value.split("-");
		arrToDate = obj.frmToDate.value.split("-");
		arrInterval = option.split(":");
		
		var one_day=1000*60*60*24;
		var fromDate = new Date(arrFromDate['0'], arrFromDate['1'], arrFromDate['2']);
		var toDate = new Date(arrToDate['0'], arrToDate['1'], arrToDate['2']);
		var interval = parseInt(arrInterval['1']);
		
		
		if(Math.ceil((toDate.getTime()-fromDate.getTime())/(one_day)) != interval)
		{
			error += "\n- 'To' date will be set exactly " + interval + " days after 'From' date.";
		}
	}
	if(error != "")
	{
		checkError(error);
		return false;
	}
	else
		return true;
}

/*****************************
Function name : changePageing
Return type : string
Date created : 5th January 2008
Date last modified : 22nd Nov 2007
Author : Vivek Avasthi
Last modified by : Vivek Avasthi
Comments : This function take to selected page
User instruction : changePageing(argStr)
************************************/
function changePaging(argStr, argPageNum)
{
  var QueryStr = argStr+argPageNum;
  location.href = QueryStr;
}

/*****************************
Function name : checkCapsLock
Return type : none
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to display alert message when caps lock is on.
User instruction : checkCapsLock( e , FieldID) 
************************************/
function checkCapsLock(e , FieldID) 
{
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='Caps Lock is ON.\n\nTo prevent entering your password incorrectly,\nYou should press Caps Lock to turn it OFF.';

	// Internet Explorer 4+
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;

	// Netscape 4
	} else if ( document.layers ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	// Netscape 6
	} else if ( document.getElementById ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	}
	
	if(document.getElementById(FieldID).value.length==0) {

		// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
		if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
			alert( myMsg );
			//return;
	
		// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
		} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
			alert( myMsg );
		//	return;
		}
		return false;
	}
}

/*****************************
Function name : validateLogin
Return type : integer
Date created : 5th April 2008
Date last modified : 5th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This is used to check member login authentications.
User instruction : validateLogin(formname)
************************************/
function validateLogin(formname)
{
	if(validateForm(formname,'frmMemberUserName','email','RisEmail', 'frmMemberPassword','password','RisSpace'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}

/*****************************
Function name : validateChangePassword
Return type : none
Date created : 15th April 2008
Date last modified : 15th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate change password form.
User instruction : validateChangePassword(formname)
************************************/
function validateChangePassword(formname)
{
	//if(validateForm(document.getElementById(formname).id,'frmMemberEmail', 'Email', 'isEmail','frmOldPassword', 'Old Password', 'R','frmNewPassword','New Password','RisPasswordfrmConfirmPassword:Confirm Password'))
	if(validateForm(document.getElementById(formname).id,'frmOldPassword', 'Old Password', 'R','frmNewPassword','New Password','RisSpace','frmConfirmPassword','Confirm New Password', 'RisEqualfrmNewPassword:New Password'))
	{			
		var flag=confirm('Are you sure you want to change password?')
		if(flag)
		{
			return true;
		}
		else
		{
			return false;		
		}
	} 
	else 
	{
		return false;
	} 
}
/*****************************
Function name : validateChangeEmail
Return type : none
Date created : 15th April 2008
Date last modified : 15th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate change email form.
User instruction : validateChangeEmail(formname)
************************************/
function validateChangeEmail(formname)
{
	if(validateForm(document.getElementById(formname).id,'frmMemberEmail', 'Email', 'isEmail'))
	{			
		var flag=confirm('Are you sure you want to change secondary email?')
		if(flag)
		{
			return true;
		}
		else
		{
			return false;		
		}
	} 
	else 
	{
		return false;
	} 
}
/*****************************
Function name : validateInviteForm
Return type : boolean
Date created : 5th April 2008
Date last modified : 5th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This is used to validate invitation form.
User instruction : validateInviteForm(formname)
************************************/
function validateInviteForm(formname)
{
	if(validateForm(document.getElementById(formname).id,'frmInviteEmail', 'Email(s)', 'R'))
	{			
		arrEmailAddress = document.getElementById('frmInviteEmail').value.split(',');
		var regEmail = /^[0-9a-z]+(([\.\-_])[0-9a-z]+)*@[0-9a-z]+(([\.\-])[0-9a-z-]+)*\.[a-z]{2,4}$/;
		var error = '';
		for(i=0;i<arrEmailAddress.length;i++)
		{
			if(!arrEmailAddress[i].match(regEmail))
			{
				error += '\n--> Email address ' + (i+1) +' is invalid';
			}
		}
		
		if(error!='')
		{
			alert(getMasterString() + error)
			return false;
		}
		else
		{
			return true;
		}
	} 
	else 
	{
		return false;
	} 
}

/*****************************
Function name : validateAdminEmailChange
Return type : boolean
Date created : 5th April 2008
Date last modified : 5th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate blog comments.
User instruction : validateBlogComments(charToCheck)
************************************/
function validateBlogComments(formname)
{
	if(validateForm(document.getElementById(formname).id,'frmBlogComments', 'Blog Comment','R'))
	{			
		return true;
	} 
	else 
	{
		return false;
	} 
}

/*****************************
Function name : validateCMSForm
Return type : boolean
Date created : 5th April 2008
Date last modified : 5th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate bar locator form.
User instruction : validateBarLocator(formname)
************************************/
function validateBarLocator(formname)
{
	if(validateForm(formname,'frmBarLocatorCity','City','R','frmDate','Date','RisDate','frmBarLocatorVenue','Venue','R','frmBarLocatorComments','Comments','R'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}

/*****************************
Function name : validateForgotPassword
Return type : boolean
Date created : 11th April 2008
Date last modified : 11th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate the CMS form.
User instruction : validateForgotPassword(formname)
************************************/
function validateForgotPassword(formname)
{
	if(validateForm(formname,'frmMemberUserName','email','RisEmail','frmSecurityCode','verification code','R'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}

/*****************************
Function name : validateRegistration
Return type : boolean
Date created : 16th April 2008
Date last modified : 16th April 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate the registration form.
User instruction : validateRegistration(formname)
************************************/
function validateRegistration(formname)
{
	if(validateForm(formname,'frmMemberUserName','Email','RisEmail','frmMemberPassword','Password','R','frmConfirmPassword','Confirm Password', 'RisEqualfrmMemberPassword:Password','frmFirstName','First Name','R','frmLastName','Last Name','R'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}

/******************************************
Function name : checkUncheckBoxes
Return type : None
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : Function will toggle the select all checkbox option.
User instruction : checkUncheckBoxes(spanChk)
******************************************/
function checkUncheckBoxes(theBox,action)
{
	elm=theBox.elements;
	
	for(i=0;i<elm.length;i++)
	{
		if(elm[i].type=="checkbox")
		{
			if(action == 'check')
			{
				elm[i].checked = true;
			}
			else
			{
				elm[i].checked = false;
			}
		}
	}
}

/******************************************
Function name : showHideTheBox
Return type : None
Date created : 10th May 2008
Date last modified : 10th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : Function is used to show hide the seacch box
User instruction : showHideTheBox(varDocumentID, varOverRideAction)
******************************************/
function showHideTheBox(FieldID, OverRideAction)
{
	if(OverRideAction)
	{
		if(OverRideAction == 'show')
		{
			document.getElementById(FieldID).style.display = 'block';
		}
		else
		{
			document.getElementById(FieldID).style.display = 'none';
		}
	}
	else
	{
		var CurrentStyle = document.getElementById(FieldID).style.display;
		if(CurrentStyle == 'none')
		{
			 document.getElementById(FieldID).style.display = 'block';	
		}
		else
		{
			 document.getElementById(FieldID).style.display = 'none';
		}
	}
}

function validateSendMessage(formname)
{
	formElements = 	document.getElementById(formname).elements;
	boolError = false;
	error = '';
	for(i=0;i<formElements.length;i++)
	{
		if(formElements[i].name == 'frmMessageToMembers[]' && formElements[i].checked == true)
		{
			boolError = true;
		}
		else if(formElements[i].value == '')
		{	
			name = formElements[i].name;
			name = name.replace('frm','');
			if(name.length > 7)
			{
				name = 'Subject';
			}
			error +='\n---> ' + name + ' is required.';
		}
	}
	
	if(!boolError)
	{
		error = '\n---> At least one network member is required.' + error;
	}
	
	if(error!="")
	{
		alert(getMasterString() + error);
		return false;
	}
	else
	{
		return true;
	}
}

/**************************************************************************
Function name : openMessage
Return type : boolean
Date created : 26th March 2008
Date last modified : 26th March 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to get Rating HOTEL Form.
User instruction : openMessage(value)
***************************************************************************/
function openMessage(value)
{ 
	doAjax('ajax_act.php','MessageID='+value,'','GET');
}
/**************************************************************************
Function name : showNews
Return type : boolean
Date created : 12th May 2008
Date last modified : 12th May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to showNews
User instruction : showNews(value)
***************************************************************************/
function showNews(source, cat)
{ 
	

doAjax('ajax_act.php','NewsSourceID='+source+'&NewsCategoryID='+cat,'ShowNews','GET',2);
}

function ShowNews(item)
{
	if(item)
	{
		document.getElementById('News').innerHTML = item;
	}
	else
	{
		document.getElementById('News').innerHTML = 'No News Available';
	}
}
/**************************************************************************
Function name : validateSendEmail
Return type : boolean
Date created : 10th May 2008
Date last modified : 10th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate send email form.
User instruction : validateSendEmail(formname)
***************************************************************************/
function validateSendEmail(formname)
{
	if(validateForm(formname,'frmMessageSubject','Subject','R','frmMessage','Message','R'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}
/**************************************************************************
Function name : validateNewThreadForm
Return type : boolean
Date created : 10th May 2008
Date last modified : 10th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate new thread form
User instruction : validateNewThreadForm(formname)
***************************************************************************/
function validateNewThreadForm(formname)
{
	if(validateForm(formname,'frmCategoryID','To','R','frmThreadCity','City','R', 'frmThreadSubject','Subject','R','frmThreadMesasge','Message','R'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}
/**************************************************************************
Function name : validatePostComment
Return type : boolean
Date created : 10th May 2008
Date last modified : 10th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to validate post comment from frontend.
User instruction : validatePostComment(formname)
***************************************************************************/
function validatePostComment(formname)
{
	if(validateForm(formname,'frmComment','Comment','R'))
	{	
		return true;
	} 
	else 
	{
		return false;
	} 
}
/**************************************************************************
Function name : viewCount
Return type : none
Date created : 13th May 2008
Date last modified : 13th May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to get to increment View Count.
User instruction : viewCount(value)
***************************************************************************/
function viewCount(value)
{ 
	doAjax('ajax_act.php','ThreadID='+value,'IncrementedCount','GET');
}

/**************************************************************************
Function name : publishSale
Return type : none
Date created : 14th May 2008
Date last modified : 14th May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to get to increment View Count.
User instruction : publishSale(value)
***************************************************************************/
function publishSale(value)
{ 
	doAjax('ajax_act.php','AdID='+value,'PublishedPost','GET');
}
/**************************************************************************
Function name : validateForSaleForm
Return type : boolean
Date created : 14th May 2008
Date last modified : 14th May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to show validate sale form
User instruction : validateForSaleForm(formname)
***************************************************************************/
function validateForSaleForm(formname)
{
	
	if(document.getElementById('frmOldImage').value == '')
	{
		if(validateForm(formname,'frmBuySellCountry','Country','R', 'frmBuySellType','Type','R','frmBuySellCategory','Category','R','frmBuySellSubject','Subject','R', 'frmBuySellDescription','Description','R','frmBuySellPrice','Price','RisNaN', 'frmBuySellImage','Image','R'))
		{	
			return true;
		} 
		else 
		{
			return false;
		}
	}
	else
	{
		if(validateForm(formname,'frmBuySellCountry','Country','R', 'frmBuySellType','Type','R','frmBuySellCategory','Category','R','frmBuySellSubject','Subject','R', 'frmBuySellDescription','Description','R','frmBuySellPrice','Price','RisNaN'))
		{	
			return true;
		} 
		else 
		{
			return false;
		}
	}
}
/**************************************************************************
Function name : getHoteInfo
Return type : boolean
Date created : 16th May 2008
Date last modified : 16th May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to get the hotel info
User instruction : getHoteInfo(formname)
***************************************************************************/
function getHoteInfo(val,id)
{ 
	doAjax('fetch_dynamic_info.php','id='+val+'&action=fetchHotelInfo','showHotelInfo','post',2);
}
/**************************************************************************
Function name : showHotelInfo
Return type : boolean
Date created : 16th May  2008
Date last modified : 16th May  2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to show the hotel info
User instruction : showHotelInfo(formname)
***************************************************************************/
function showHotelInfo(item)
{
	document.getElementById('hotelInfo').innerHTML = item;	
}
/**************************************************************************
Function name : doRating
Return type : boolean
Date created : 16th May 2008
Date last modified : 16th May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to for the rating for hotel
User instruction : doRating(formname)
***************************************************************************/
function doRating(hotelid,rating)
{
	if(rating == 0)
	{
		alert('Please select the rating');
		return false;
	}
	doAjax('fetch_dynamic_info.php','id='+hotelid+'&rating='+rating+'&action=rating','showRating(\''+ hotelid+'\',\''+ rating+'\')','post');
}
/**************************************************************************
Function name : showRating
Return type : boolean
Date created : 16th May 2008
Date last modified : 16th May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to show the response data
User instruction : showRating(formname)
***************************************************************************/
function showRating(hotelid,rating,item)
{
	var id = 'Rating'+hotelid;
	document.getElementById(id).innerHTML = '('+item.substring(12,18)+')';
	document.getElementById('yourRating').innerHTML = '<table width=\'100%\' style=\'padding:0px 0px 0px 0px ;\' border=\'0\' cellspacing=\'0\' cellpadding=\'0\'><tr><td valign=\'top\' width=\'50%\' style=\'text-align:left;padding:0px 0px 0px 0px ;\'><strong>Your Rating:</strong></td><td width=\'50%\' style=\'text-align:left;padding:0px 0px 0px 0px ;;\'><strong>'+rating+'</strong></td></tr></table>';
	document.getElementById('rating').innerHTML = item;
	document.getElementById('rated').options[0].selected = true;
}
/**************************************************************************
Function name : postComments
Return type : boolean
Date created : 16th May 2008
Date last modified : 31th May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This ia a ajax funxtion use for the posting the comments
User instruction : postComments(formname)
***************************************************************************/
function postComments(hotelid,comment)
{
	if(trim(comment) == '')
	{
		alert('Please enter the comments.');
		return false;
	}
	doAjax('fetch_dynamic_info.php','id='+hotelid+'&comment='+comment+'&action=postComment','showComment','post');
}
/**************************************************************************
Function name : showComment
Return type : boolean
Date created : 14th May 2008
Date last modified : 14th May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used by the ajax function which returns the response to the inner html
User instruction : showComment()
***************************************************************************/
function showComment(item)
{
	document.getElementById('comment').innerHTML = item;	
	document.getElementById('frmPostComment').value = ' ';	
}
/**************************************************************************
Function name : validateAddItem
Return type : boolean
Date created : 14th May 2008
Date last modified : 14th May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate to Add Item.
User instruction : validateAddItem()
***************************************************************************/
function validateAddItem(formname)
{
	if(validateForm(formname,'frmName','Name','R','frmCity','City','R','frmEmail','Email','isEmail'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
/**************************************************************************
Function name : validatePostJob
Return type : boolean
Date created : 22nd May 2008
Date last modified : 22nd May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate Post job form
User instruction : validatePostJob()
***************************************************************************/
function validatePostJob(formname)
{
	if(validateForm(formname,'frmJobIndustry','Industry','R','frmJobTitle','Job Title','R','frmJobKeywords','Job Keywords', 'R','frmJobCity','City','R','frmJobCountry','Country','R','frmJobSalaryMin','Salary-Minimum','isNan','frmJobSalaryMax','Salary-Maximum','isNan','frmJobContactName','Contact Name','R','frmJobContactPhone','Contact Phone','R','frmJobDescription','Job Description','R'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
/**************************************************************************
Function name : validateJobCompany
Return type : boolean
Date created : 22nd May 2008
Date last modified : 22nd May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate job company
User instruction : validateJobCompany()
***************************************************************************/
function validateJobCompany(formname)
{
	if(validateForm(formname,'frmCompanyName','Title / Name','R','frmCompanyAddress','Address','R','frmCompanyURL','URL', 'RisUrl','frmCompanyDescription','Description','R'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
/**************************************************************************
Function name : validateSaleForm
Return type : boolean
Date created : 22nd May 2008
Date last modified : 22nd May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate For Sale Form
User instruction : validateSaleForm()
***************************************************************************/
function validateSaleForm(formname)
{
	if(validateForm(formname,'frmPropertyCity','City','R','frmPropertyExactLocation','Exact Location','R','frmPropertyAddress','Address', 'R','frmPropertyCountry','Country','R', 'frmPropertyTitle','Title','R','frmPropertyDescription','Description','R','frmPropertyLongDescription','Long Description', 'R','frmPropertyRoom','Room','RisNaN','frmPropertyBathroom','Baths','RisNaN','frmPropertyFloor','Floors','RisNaN','frmPropertySize','Size','RisNaN','frmPropertyPrice','Price','RisNaN'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
/**************************************************************************
Function name : validateForRentForm
Return type : boolean
Date created : 22nd May 2008
Date last modified : 22nd May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate For Rent Form
User instruction : validateForRentForm()
***************************************************************************/
function validateForRentForm(formname)
{
	if(validateForm(formname,'frmPropertyCity','City','R','frmPropertyExactLocation','Exact Location','R','frmPropertyAddress','Address', 'R','frmPropertyCountry','Country','R', 'frmPropertyTitle','Title','R','frmPropertyDescription','Description','R','frmPropertyLongDescription','Long Description', 'R','frmPropertyRoom','Bedroom(s)','RisNaN','frmPropertySleep','Sleeps','RisNaN','frmPropertyBathroom','Bathroom(s)','RisNaN','frmPropertyFloor','Floors','RisNaN','frmPropertyRentStartDate','Starting Date','RisDate','frmPropertyRentEndDate','Ending Date','RisDate','frmPropertyRentRate','Rate','RisNaN','frmPropertyExtraRateForGuest','Cost per Extra Guest','RisNaN'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
/**************************************************************************
Function name : validateContactInfoForm
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate Contact Info of Member
User instruction : validateContactInfoForm()
***************************************************************************/
function validateContactInfoForm(formname)
{
	if(validateForm(formname,'frmAddress1','Address 1','R','frmAddress2','Address 2','R','frmCity','City', 'R','frmRegion','Region','R', 'frmCountry','Country','R','frmPostelCode','Postel Code','R'))
	{
		return true;
	}
	else
	{
		return false;
	}
}
/**************************************************************************
Function name : validateMemberPhoto
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to validate PHOTO FORM of Member
User instruction : validateMemberPhoto()
***************************************************************************/
function validateMemberPhoto(formname)
{
	if(document.getElementById('frmOldPhoto').value == '')
	{
		if(validateForm(formname,'frmMemberPhoto','Photo','R'))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
//function checkNumberOrNot(value, id)
//{
//	if(isNaN(value))
//	{
//		document.getElementById(id).value = '';
//		return false;
//	}
//}
/**************************************************************************
Function name : ViewEventOnCalender
Return type : boolean
Date created : 26th March 2008
Date last modified : 26th March 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to View Event of perticular date.
User instruction : ViewEventOnCalender(value)
***************************************************************************/
function ViewEventOnCalender(value)
{ 
	var EventVal = value.split('?');
	var EventID = EventVal[1].split('=');
	doAjax('ajax_act.php','EventID='+EventID[1],'DisplayEvent','GET',2);
}
/**************************************************************************
Function name : DisplayEvent
Return type : boolean
Date created : 26th March 2008
Date last modified : 26th March 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to Display Event Details
User instruction : DisplayEvent()
***************************************************************************/ 
function DisplayEvent(item)
{	
	if(item)
	{
		document.getElementById('ShowEvent').innerHTML = item;
	}
}

/**************************************************************************
Function name : showImageFields
Return type : boolean
Date created : 7th April 2008
Date last modified : 7th April 2008
Author : Sandeep Kumar
Last modified by : Sandeep Kumar
Comments : This function is used to show image fields in House and Flats Sale Form
User instruction : showImageFields(value)
***************************************************************************/ 
function showImageFields(value)
{	
	var imageFields = '';
	if(value == '')
	{
		document.getElementById('ImageFields').innerHTML = '';
		document.getElementById('ImageFields').style.display = 'none';	
	}
	else
	{
		for(i=0; i<value; i++)
		{
			if((i % 2)== 0)
			{
				Class = 'class="down_1"';
			}
			else
			{
				Class = 'class="up_1"';
			}
			imageFields = imageFields + '<tr style=\"border-bottom:none;\" '+Class+' ><td width=\"37%\"> Name</td><td style=\"border-right:none;\"><input name=\"frmHouseImageName'+i+'\" id=\"frmHouseImageName'+i+'\"  style=\"width:150px; float:left;\" type=\"text\" value=\"\" /></td><td style=\"vertical-align:top;border-left:none;\"><input name=\"frmHouseImage'+i+'\" id=\"frmHouseImage'+i+'\" type=\"file\" value=\"\" onkeypress=\"return false;\" /></td></tr>';
		}
		ImageFieldInnerHTML = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:100%; margin-top:0px;padding-top:0px; padding-left:0px; float:left;\ border:none;" class="\my_page_table\">'+imageFields+'</table>';
		document.getElementById('ImageFields').innerHTML = ImageFieldInnerHTML;
		document.getElementById('ImageFields').style.display = 'block';
	}
	
}


function getPlanDetails(value)
{
	doAjax('ajax_act.php','pid='+value,'showPlanDetails','post');
}

function showPlanDetails(item)
{
	if(item)
	{
		document.getElementById('MainDiv').innerHTML = item;
	}
}
/**************************************************************************
Function name : displayBox
Return type : boolean
Date created : 20th May 2008
Date last modified : 21th May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to display the box
User instruction : displayBox(id,btn)
***************************************************************************/ 
function displayBox(id,btn)
{
	document.getElementById(id).style.display = '';
	document.getElementById(btn).style.display = 'none';
}

/**************************************************************************
Function name : validatePersonalInfo
Return type : boolean
Date created : 20th May 2008
Date last modified : 21th May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to validate the
User instruction : validatePersonalInfo(formname)
***************************************************************************/ 
function validatePersonalInfo(formname)
{
	if(document.getElementById('sec5').style.display=='')
	{
		if(validateForm(formname,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmRelationship','RelationShip Status', 'R','frmAddressCity','City','R','frmAddressCountry','Country','R','frmAddressCity1','City One','R','frmAddressCountry1','Country One','R','frmAddressCity2','City Two','R','frmAddressCountry2','Country Two','R','frmAddressCity3','City Three','R','frmAddressCountry3','Country Three','R','frmAddressCity4','City Four','R','frmAddressCountry4','Country Four','R','frmAddressCity5','City Five','R','frmAddressCountry5','Country Five','R'))
		{document.getElementById(formname).submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else if(document.getElementById('sec4').style.display=='')
	{
		if(validateForm(formname,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmRelationship','RelationShip Status', 'R','frmAddressCity','City','R','frmAddressCountry','Country','R','frmAddressCity1','City One','R','frmAddressCountry1','Country One','R','frmAddressCity2','City Two','R','frmAddressCountry2','Country Two','R','frmAddressCity3','City Three','R','frmAddressCountry3','Country Three','R','frmAddressCity4','City Four','R','frmAddressCountry4','Country Four','R'))
		{document.getElementById(formname).submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else if(document.getElementById('sec3').style.display=='')
	{
		if(validateForm(formname,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmRelationship','RelationShip Status', 'R','frmAddressCity','City','R','frmAddressCountry','Country','R','frmAddressCity1','City One','R','frmAddressCountry1','Country One','R','frmAddressCity2','City Two','R','frmAddressCountry2','Country Two','R','frmAddressCity3','City Three','R','frmAddressCountry3','Country Three','R'))
		{document.getElementById(formname).submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else if(document.getElementById('sec2').style.display=='')
	{
		if(validateForm(formname,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmRelationship','RelationShip Status', 'R','frmAddressCity','City','R','frmAddressCountry','Country','R','frmAddressCity1','City One','R','frmAddressCountry1','Country One','R','frmAddressCity2','City Two','R','frmAddressCountry2','Country Two','R'))
		{document.getElementById(formname).submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else if(document.getElementById('sec1').style.display=='')
	{
		if(validateForm(formname,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmRelationship','RelationShip Status', 'R','frmAddressCity','City','R','frmAddressCountry','Country','R','frmAddressCity1','City One','R','frmAddressCountry1','Country One','R'))
		{
			document.getElementById(formname).submit();
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		if(validateForm(formname,'frmFirstName','First Name','R','frmLastName','Last Name','R','frmRelationship','RelationShip Status', 'R','frmAddressCity','City','R','frmAddressCountry','Country','R'))
		{
			document.getElementById(formname).submit();
			return true;
		}
		else
		{
			return false;
		}
	}
}


function setHiddenValue(id)
{
	alert(document.getElementById(id).value);
	document.getElementById(id).value = 'Active';
	alert(document.getElementById(id).value);
}
/**************************************************************************
Function name : showEmploymentHistory
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Gulshan Verma
Last modified by : Grin4ishin Vladimir
Comments : This function is used to make the employementbox
User instruction : showEmploymentHistory(formname)
***************************************************************************/ 
function showEmploymentHistory(countValue)
{
	var fromOptionString;
	var TitleOptionString;
	if(countValue < 15)
	{
		document.getElementById('frmCount').value = ++countValue;
		divid ='other_emplone'+countValue;
		for(year = 1985; year <=2008 ;year++ )
		{
			fromOptionString +='<option value="'+year+'">'+year+'</option>';
			
		}
		TitleOptionString ='<option value=\"CEO/Chairman\">CEO/Chairman</option><option value=\"Owner\">Owner</option><option value=\"Vice President\">Vice President</option><option value=\"Executive\">Executive</option><option value=\"Managing director\">Managing director</option><option value=\"Director\">Director</option><option value=\"Partner\">Partner</option><option value=\"Manager\">Manager</option><option value=\"Associate\">Associate</option><option value=\"Analyst\">Analyst</option><option value=\"Assistant\">Assistant</option><option value=\"other\">other</option>';
        tableId = 'table'+countValue;
        link = '<a href="#" onclick ="showhideTable(\''+tableId+'\'); return false;">[ X ]</a>';
        row = "<td align='right'>"+link+"</td>"

		
		var html = '<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"my_page_table\" id=\"'+tableId+'\"><tr class=\"down_1\"><td style=\"width:28%\"><span class="red_text">*</span> Employer </td><td><input type=\"text\" name=\"frmEmployer'+countValue+'\"  id=\"frmEmployer'+countValue+'\"  /></td>'+row+'</tr><tr class=\"up_1\"><td><span class="red_text">*</span> Title </td><td><select  onchange="openOther(this.value,\''+divid+'\');" name=\"frmEmployerTitle'+countValue+'\" id=\"frmEmployerTitle'+countValue+'\">'+TitleOptionString+'</select><div id=\"'+divid+'\" style="display:none;"><small>If other, please specify</small><input type=\"text\" name=\"frmEmployerOtherTitle'+countValue+'\"  id=\"frmEmployerOtherTitle'+countValue+'\" /></div></td></tr><tr class=\"up_1\"><td><span class="red_text">*</span> From </td><td><select name=\"frmEmployerFrom'+countValue+'\" id=\"frmEmployerFrom'+countValue+'\"><option value=\"1\">Select</option>'+fromOptionString+'</select></td></tr><tr class=\"up_1\"><td><span class="red_text">*</span>  To </td><td><select name=\"frmEmployerTo'+countValue+'\" id=\"frmEmployerTo'+countValue+'\"><option value=\"1\">Select</option>'+fromOptionString+'</select></td></tr><tr class="up_1"><td colspan="2"></td></tr></table>';
		document.getElementById('EmploymentHistory'+countValue).innerHTML = html;
		document.getElementById('EmploymentHistory'+countValue).style.display = 'block';
		if(countValue == 15)
		{
		document.getElementById('btn_hide').style.display = 'none';
		}
		
	}
	else
	{
		document.getElementById('btn_hide').style.display = 'none';
		return false;
	}
}
/**************************************************************************
Function name : showAcademicHistory
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Gulshan Verma
Last modified by : 
Comments : This function is used to make the academic box
User instruction : showAcademicHistory(formname)
***************************************************************************/ 
function showAcademicHistory(countValue)
{
    var academicOptionString;
    var fromOptionString;
    var TitleOptionString;
    academicOptionString = '<option value=\"High School\">High School</option><option value=\"Phd\">Phd</option><option value=\"Masters\">Masters</option><option value=\"MD\">MD</option><option value=\"Law\">Law</option><option value=\"Bachelors\">Bachelors</option><option value="other">other</option>';
    for(year = 1910; year <=2015 ;year++ )
        {
            fromOptionString +='<option value="'+year+'">'+year+'</option>';
        }
    if(countValue < 5)
    {
        document.getElementById('frmCountTwo').value = ++countValue;
        divid ='other_One'+countValue;
        
        
        tableId = 'table'+countValue;
        link = '<a href="#" onclick ="showhideTable2(\''+tableId+'\'); return false;">[ X ]</a>';
        row = "<td align='right'>"+link+"</td>"
        
        
        var html = '<table style=\"width:99%;\" align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"my_page_table\" id=\"'+tableId+'\"><tr class=\"down_1\"><td style=\"width:28%\"><span class="red_text">*</span> Academic Level</td><td><select onchange="openOther(this.value,\''+divid+'\');" name=\"frmAcademicLevel'+countValue+'\" id=\"frmAcademicLevel'+countValue+'\">'+academicOptionString+'</select><div id=\"'+divid+'\" style="display:none;"><small>If other, please specify</small><input type=\"text\" name=\"frmAcedemicLevelOther'+countValue+'\" id=\"frmAcedemicLevelOther'+countValue+'\" /></div></td>'+row+'</tr><tr class=\"up_1\"><td><span class="red_text">*</span> School Name</td><td><input type=\"text\" name=\"frmSchoolName'+countValue+'\" id=\"frmSchoolName'+countValue+'\" /></td></tr><tr class=\"up_1\"><td><span class="red_text">*</span> Graduation Year</td><td><select name=\"frmGraduationYear'+countValue+'\" id=\"frmGraduationYear'+countValue+'\">'+fromOptionString+'</select></td></tr><tr class="up_1"><td colspan="2"></td></tr></table>';
        document.getElementById('AcademicHistory'+countValue).innerHTML = html;
        document.getElementById('AcademicHistory'+countValue).style.display = 'block';
        if(countValue == 5)
        {
        document.getElementById('school_bt_hide').style.display = 'none';            
        }

    }else
    {
        document.getElementById('school_bt_hide').style.display = 'none';
        return false;
    }
        
}
/**************************************************************************
Function name : validateAcademicProfessionalFrm
Return type : boolean
Date created : 22nd May 2008
Date last modified : 22nd May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to validate the
User instruction : validateAcademicProfessionalFrm(formname)
***************************************************************************/ 
function validateAcademicProfessionalFrm(formname)
{
   var MasterString = getMasterString();
   var errorString = '';
   var boolfocus = false;
   var elementID ;
   var EmplCount = document.getElementById('frmCount').value;
   var AcademicCount = document.getElementById('frmCountTwo').value;
   if(document.getElementById(formname).frmEmployementStatus.value == '')
   {
   errorString += '--> Employment Status is required.\n';  
   boolfocus = true; 
   elementID = 'frmEmployementStatus'; 
   }
   if(document.getElementById(formname).frmIndustry.value == '')
   {
  	 errorString += '--> Industry is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmIndustry'; 
	 }
   }
   if(document.getElementById(formname).frmEmployeeName.value == '')
   {
  	 errorString += '--> Employee Name is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmEmployeeName'; 
	 }
   }
   if(document.getElementById(formname).frmMainTitle.value == '')
   {
  	 errorString += '--> Title is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmMainTitle'; 
	 }
   }
   if(document.getElementById(formname).frmMainTitle.value == 'other')
   {
	   if(document.getElementById(formname).frmOtherTitle.value == '')
	   {
		 errorString += '-->Other Title is required.\n';  
		 if(boolfocus != true)
		 {
			 boolfocus = true; 
			elementID = 'frmOtherTitle'; 
		 }
	   }
   }
   if(document.getElementById(formname).frmMainFrom.value == '')
   {
  	 errorString += '--> Year is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmMainFrom'; 
	 }
   }

	for(i=1; i<=EmplCount; i++)
	{

		   if(document.getElementById('frmEmployer'+i).value == '')
		   {
			 errorString += '--> Emoployee Name is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmEmployer'+i; 
			 }
		   }
		   if(document.getElementById('frmEmployerTitle'+i).value == '')
		   {
			 errorString += '--> Title is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmEmployerTitle'+i; 
			 }
		   }
		  if(document.getElementById('frmEmployerTitle'+i).value == 'other')
		   {
			   if(document.getElementById('frmEmployerOtherTitle'+i).value == '')
			   {
				 errorString += '--> Other Title is required.\n';  
				 if(boolfocus != true)
				 {
					 boolfocus = true; 
					elementID = 'frmEmployerOtherTitle'+i; 
				 }
			   }
		   }
		   if(document.getElementById('frmEmployerFrom'+i).value == '')
		   {
			 errorString += '--> From Year is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmEmployerFrom'+i; 
			 }
		   }
		   if(document.getElementById('frmEmployerTo'+i).value == '')
		   {
			 errorString += '--> To Year is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmEmployerTo'+i; 
			 }
		   }
	}
   if(document.getElementById(formname).frmMainAcademicLevel.value == '')
   {
  	 errorString += '--> Academic Level is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmMainAcademicLevel'; 
	 }
   }
      if(document.getElementById(formname).frmMainAcademicLevel.value == 'other')
	  {
			   if(document.getElementById(formname).frmMainAcademicLevelOther.value == '')
			   {
				 errorString += '--> Academic Level Other is required.\n';  
				 if(boolfocus != true)
				 {
					 boolfocus = true; 
					elementID = 'frmMainAcademicLevelOther'; 
				 }
			   }
	  }
   
   if(document.getElementById(formname).frmMainSchoolName.value == '')
   {
  	 errorString += '--> School Name is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmMainSchoolName'; 
	 }
   }
   if(document.getElementById(formname).frmMainGraduationYear.value == '')
   {
  	 errorString += '--> Year is required.\n';  
     if(boolfocus != true)
     {
	     boolfocus = true; 
        elementID = 'frmMainGraduationYear'; 
	 }
   }
   for(i=1; i<=AcademicCount ; i++)
	{
		if(document.getElementById('frmAcademicLevel'+i).value == '')
		{
		  	 errorString += '--> Academic Level is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmAcademicLevel'+i; 
			 }
		}
		if(document.getElementById('frmAcademicLevel'+i).value == 'other')
		{
				if(document.getElementById('frmAcedemicLevelOther'+i).value == '')
				{
					 errorString += '--> Academic Other Level is required.\n';  
					 if(boolfocus != true)
					 {
						 boolfocus = true; 
						elementID = 'frmAcedemicLevelOther'+i; 
					 }
				}
		}
	if(document.getElementById('frmSchoolName'+i).value == '')
		{
		  	 errorString += '--> School Name is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmSchoolName'+i; 
			 }
		}
		if(document.getElementById('frmGraduationYear'+i).value == '')
		{
		  	 errorString += '--> Year is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				 elementID = 'frmGraduationYear'+i; 
			 }
		}
   }
   if(errorString == '')
   {
	 document.getElementById(formname).submit();
   }
   if(errorString  != '')
   {
	  alert(MasterString+'\n'+errorString);   
	  document.getElementById(elementID).focus();
	  return false;   
   }
}
/**************************************************************************
Function name : showClubBox
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to make the club box
User instruction : showClubBox(formname)
***************************************************************************/ 
function showClubBox(countValue)
{
	var academicOptionString;
	var ClubOptionString;
	var TitleOptionString;
	var divid ;
	ClubOptionString ='<option value="">Select..</option><option value="Athletic club">Athletic club</option><option value="Beach club">Beach club</option><option value="Yacht club">Yacht club</option><option value="Country club">Country club</option><option value="Golf club">Golf club</option><option value="City club">City club</option><option value="Nightclub">Nightclub</option><option value="Tennis club">Tennis club</option><option value="University club">University club</option><option value="other">other</option>';		
	if(countValue < 5)
	{
		document.getElementById('frmCount').value = ++countValue;
		divid ='other_'+countValue;
		var html = '<table style="width:100%" border="0" cellspacing="0" cellpadding="0"><tr class="down_1"><td style="width:28%"><span class="red_text">*</span>  Club Type</td><td><select onchange="openOther(this.value,\''+divid+'\');"  name=\"frmClubType'+countValue+'\" id=\"frmClubType'+countValue+'\">'+ClubOptionString+'</select><div id=\"'+divid+'\" style="display:none;"><small>If other, please specify</small><input type="text" name=\"frmClubOther'+countValue+'\" id=\"frmClubOther'+countValue+'\" /></div></td></tr><tr class="up_1"><td> <span class="red_text">*</span> Club Name</td><td><input type="text" name=\"frmClubName'+countValue+'\" id=\"frmClubName'+countValue+'\" /></td></tr></table>';
		//alert(html);
		document.getElementById('ClubBox'+countValue).innerHTML = html;
		document.getElementById('ClubBox'+countValue).style.display = 'block';
		if(countValue == 5)
		{
			document.getElementById('club_hide').style.display = 'none';			
		}
	}else
	{
		document.getElementById('club_hide').style.display = 'none';
		return false;
	}
}
	
/**************************************************************************
Function name : validateClubForms
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to validate the club forms
User instruction : validateClubForms(formname)
***************************************************************************/ 
function validateClubForms(formname)
{
	//alert('a');
   var MasterString = getMasterString();
   var errorString = '';
   var boolfocus = false;
   var elementID ;
   var EmplCount  = document.getElementById('frmCount').value; 
	 if(document.getElementById(formname).frmMainClubType.value == '')
	   {
	   errorString += '--> Club Type is required.\n';  
	   boolfocus = true; 
	   elementID = 'frmMainClubType'; 
	   }
	   	 if(document.getElementById(formname).frmMainClubType.value == 'other')
		 {
			   if(document.getElementById(formname).frmOtherType.value == '')
			   {
				 errorString += '--> Other Type is required.\n';  
				 if(boolfocus != true)
				 {
					 boolfocus = true; 
					elementID = 'frmOtherType'; 
				 }
			   }  
		 }
  	   if(document.getElementById(formname).frmMainClubName.value == '')
	   {
		 errorString += '--> Club Name is required.\n';  
		 if(boolfocus != true)
		 {
			 boolfocus = true; 
			elementID = 'frmMainClubName'; 
		 }
	   }  
	for(i=1; i<=EmplCount ; i++)
	{
		   if(document.getElementById('frmClubType'+i).value == '')
		   {
			 errorString += '--> Club Type is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmClubType'+i; 
			 }
		   }
		   if(document.getElementById('frmClubType'+i).value == 'other')		   
		   {
			   if(document.getElementById('frmClubOther'+i).value == '')
			   {
				 errorString += '--> Club Type Other is required.\n';  
				 if(boolfocus != true)
				 {
					 boolfocus = true; 
					elementID = 'frmClubOther'+i; 
				 }
			   }
		   }
		   if(document.getElementById('frmClubName'+i).value == '')
		   {
			 errorString += '--> Club Name is required.\n';  
			 if(boolfocus != true)
			 {
				 boolfocus = true; 
				elementID = 'frmClubName'+i; 
			 }
		   }
	}
   
   if(errorString == '')
   {
	 document.getElementById(formname).submit();
   }
   if(errorString  != '')
   {
	  alert(MasterString+'\n'+errorString);   
	  document.getElementById(elementID).focus();
   }	
	 // return false;   
}
/**************************************************************************
Function name : openOther
Return type : boolean
Date created : 23rd May 2008
Date last modified : 23rd May 2008
Author : Gulshan Verma
Last modified by : Gulshan Verma
Comments : This function is used to show the box
User instruction : openOther(val,id)
***************************************************************************/ 
function openOther(val,id)
{
	if(val=='other')
	{
			 document.getElementById(id).style.display = 'block';
	}
	else
	{
			document.getElementById(id).style.display ='none';
	}
}

/*****************************
Function name : checkSearchDate
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to put check on search date.
User instruction : checkSearchDate(obj)
************************************/
function updateConn(value, action, targetID, text)
{
	if(askConfirm(text + ' this request'))
	{
		doAjax('ajax_act.php','id='+value+'&act='+action,'showUpdateResult(\''+ targetID+'\')','post','2');
	}
	else
	{
		return false;
	}
}

/*****************************
Function name : checkSearchDate
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to put check on search date.
User instruction : checkSearchDate(obj)
************************************/
function showUpdateResult(targetID, item)
{
	document.getElementById(targetID).innerHTML = item;
}

/*****************************
Function name : checkSearchDate
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to put check on search date.
User instruction : checkSearchDate(obj)
************************************/
function sendConnectionRequest(value, targetID, action)
{
	if(askConfirm(action + ' connection request'))
	{
		doAjax('ajax_act.php','id='+value+'&action=send','showRequestResult(\''+ targetID+'\')','post','2');
	}
	else
	{
		return false;
	}
}

/*****************************
Function name : checkSearchDate
Return type : boolean
Date created : 5th January 2008
Date last modified : 5th January 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to put check on search date.
User instruction : checkSearchDate(obj)
************************************/
function showRequestResult(targetID, item)
{
	document.getElementById(targetID).innerHTML = item;
}

/*****************************
Function name : resendConnectionRequest
Return type : boolean
Date created : 25th May 2008
Date last modified : 25th May 2008
Author : Charanjeet Singh
Last modified by : Charanjeet Singh
Comments : This function is used to resend connection request that has been previously ignored.
User instruction : resendConnectionRequest(member, net_member, targetID)
************************************/
function resendConnectionRequest(member, net_member, targetID)
{
	if(askConfirm('resend connection request'))
	{
		doAjax('ajax_act.php','mid='+member+'&nid='+net_member+'&action=resend','showRequestResult(\''+ targetID+'\')','post','2');
	}
	else
	{
		return false;
	}
}