/*
	Copyright Infinite Solutions Co.,Ltd 2009;
	mediaweb.js v 2.0 2009.06.03;
	Infinite Solutions JS Main File
*/
function toconvert(otoutf,oelement)
{
	var sourceareastr = oelement.value;
	var strlen = sourceareastr.length;
	var str="";
	if (otoutf=='wintoutf') { 
		 for (i = 0; i < strlen;  i++) { 
		  	var codestr = sourceareastr.charCodeAt(i);
		   	switch(codestr) {
				case 184: codestr=1105;break; 
				case 168: codestr=1025;break; 
			
				case 175: codestr=1198; break; 
				case 191: codestr=1199; break; 
				
				case 170: codestr=1256; break; 
				case 186: codestr=1257; break; 
		   }
		   if (256>codestr && codestr>191) 
		   		codestr=codestr+848;
		   switch(codestr) {
				case 1111: codestr=1199;break;   
				case 1031: codestr= 1198; break; 
				
				case 1108: codestr=1257; break; 
				case 1028: codestr=1256; break; 
		   }
			   str=str+String.fromCharCode(codestr);
		} 
		
		oelement.value=str;	   	   
	 
	} 
	else 
		if (otoutf=='utftowin') { 
			   for (i = 0; i < strlen;  i++) { 
					var codestr = sourceareastr.charCodeAt(i);
					switch(codestr) {
						case 1025: codestr=168;break; 
						case 1105: codestr=184;break; 
							
						case 1198: codestr=175; break; 
						case 1199: codestr=191; break; 
						
						case 1256: codestr=170; break; 
						case 1257: codestr=186; break; 
						
						case 415: codestr=170; break; 
						case 629: codestr=186; break; 
					}
					if (1280>codestr && codestr>1023) 
							codestr=codestr-848; 
					str=str+String.fromCharCode(codestr);
		   		}
	   			
				oelement.value=str;
	
	   		
        }
		
}

function checkFormConvert(oCheckformId)
{
	var formError=0;
	var Checkform=document.getElementById(oCheckformId);
	var oldElemen;
	if(Checkform)
	{
		inputInd=0;		
		while(Checkform.getElementsByTagName('input')[inputInd])
		{
			
			var testinput=Checkform.getElementsByTagName('input')[inputInd];
			if(testinput.type!='file'){
				toconvert('wintoutf',testinput);
			}	
				
				if (testinput.className.indexOf("im_extvalidEmail")!=-1 ) {
					if(!validateEmail(testinput.id)){
						formError++;
					}
				}
				else
					if (testinput.className.indexOf("im_extvalidREEmail")!=-1 || testinput.className.indexOf("im_extvalidREpass")!=-1 ) {
						if(oldElemen && oldElemen.value!=testinput.value || testinput.value==''){
							if (testinput.className.indexOf("im_extvalidREEmail")!=-1)
								validateInputRE(testinput.id,"im_extvalidREEmail");
							else
								validateInputRE(testinput.id,"im_extvalidREpass");
							formError++;
						}
					}
					else
						if (testinput.className.indexOf("im_extvalid")!=-1 ) {
							if(!validateInput(testinput.id)){
								formError++;						
							}
						}
				
				oldElemen=testinput;
			
			inputInd++;
		}
		
		textareaInd=0;
		while(Checkform.getElementsByTagName('textarea')[textareaInd])
		{			
			var testarea=Checkform.getElementsByTagName('textarea')[textareaInd];						
			toconvert('wintoutf',testarea);	
			
			if (testarea.className.indexOf("im_extvalid")!=-1 ) {
				if(!validateInput(testarea.id)){
					formError++;						
				}
			}
		
			textareaInd++;
		}		
	}
	//alert(formError);
	if(formError==0)
		return true;
	else	
		return false;
}


	function alertshow(otit,otext){	
		window.scrollTo(0,0);
		if (parseInt(navigator.appVersion)>3) 
		{
			 if (navigator.appName=="Netscape") 
			 {
				  winW = window.innerWidth;					 
				  winH = window.innerHeight;
			 }
			else
			 if (navigator.appName.indexOf("Microsoft")!=-1 ) 
			 {
				  winW = document.body.offsetWidth;					  
				  winH = document.body.offsetHeight;
			 }
			else
			 if(window.XMLHttpRequest)
			 {
				if(document.body.offsetHeight)
				 winH = document.body.offsetHeight;
				if(window.innerWidth)
				 winW = window.innerWidth;
			 }
			 			 			 
		}
	
		newPosX=(winW-600)/2;
		newPosY=100;
		if(document.getElementById('ext-comp-MSG1002')){
			
			if(document.getElementById('ext-genMSG57') && otit!=''){
				document.getElementById('ext-genMSG57').innerHTML=otit;
			}
			if(document.getElementById('ext-genMSG68') && otext!=''){
				document.getElementById('ext-genMSG68').innerHTML=otext;
			}
			if(document.getElementById('ext-genMSG56')){
				document.getElementById('ext-genMSG56').setAttribute("width",winW);
				document.getElementById('ext-genMSG56').setAttribute("height",winH);	
				document.getElementById('ext-genMSG56').style.display='block';
			}
			
			
			document.getElementById('ext-comp-MSG1002').style.top=newPosY+'px';
			document.getElementById('ext-comp-MSG1002').style.left=newPosX+'px';
			document.getElementById('ext-comp-MSG1002').style.visibility='visible';
			
		}
	}
	
	function alertclose(){
		if(document.getElementById('ext-comp-MSG1002')){			
			document.getElementById('ext-comp-MSG1002').style.top='-1000px';
			document.getElementById('ext-comp-MSG1002').style.left='-1000px';
			document.getElementById('ext-comp-MSG1002').style.visibility='hidden';
			document.getElementById('ext-genMSG56').style.display='none';
		}	
	}
	
	
	function alertchange(otype){
		
		if(otype=='alert'){
			if(document.getElementById('ext-genMSGOK21')){		
				document.getElementById('ext-genMSGOK21').className='x-panel-btn-td';
				document.getElementById('ext-genMSGCANCEL45').className='x-panel-btn-td x-hide-offsets';
				document.getElementById('ext-genMSGlogo').className='ext-mb-fix-cursor';
			}	
		}
		else
			if(otype=='window'){
				if(document.getElementById('ext-genMSGOK21')){		
					document.getElementById('ext-genMSGOK21').className='x-panel-btn-td x-hide-offsets';
					document.getElementById('ext-genMSGCANCEL45').className='x-panel-btn-td';
					document.getElementById('ext-genMSGlogo').className='';
				}
			}
			else
				if(otype=='form'){
					if(document.getElementById('ext-genMSGOK21')){		
						document.getElementById('ext-genMSGOK21').className='x-panel-btn-td x-hide-offsets';
						document.getElementById('ext-genMSGCANCEL45').className='x-panel-btn-td x-hide-offsets';
						document.getElementById('ext-genMSGlogo').className='';
					}
				}
	}
	
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	function ltrim(stringToTrim) {
		return stringToTrim.replace(/^\s+/,"");
	}
	function rtrim(stringToTrim) {
		return stringToTrim.replace(/\s+$/,"");
	}


	function validateEmail(email) {
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   //var address = document.forms[form_id].elements[email].value;
	   var address = document.getElementById(email);
	    var address2 = trim(document.getElementById(email).value);
		
		
	   if(reg.test(address2) == false) {
		  //alert('Invalid Email Address');		  
		  address.className='im_extvalidEmail im_errorValid';
		  return false;
	   }
	   else{
		   address.className='im_extvalidEmail';
		   document.getElementById(email).value=address2;
	   	   return true;
	   }
	}
	
	function validateInputRE(oid,oclass){
		var address = document.getElementById(oid);
		address.className=oclass+' im_errorValid';
	}
	
	function validateEmailImg(email,email2){
		if(validateEmail(email))
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Tick.png' border=0 width=16 height=16 />"; 
		else 
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Delete.png' border=0 width=16 height=16 />";	
	}
	
	function validateEmailImg2(email,email2,email1){
		
		if(validateEmail(email1)){
		
			if(document.getElementById(email1).value==document.getElementById(email).value)
				document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Tick.png' border=0 width=16 height=16 />"; 
			else
				document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Delete.png' border=0 width=16 height=16 />";
		}
		else 
			document.getElementById(email2).innerHTML="<img src='"+vsubpath+"/isimage/Delete.png' border=0 width=16 height=16 />";	
	}
	
	function validateInput(email) {
	   
	   var address = document.getElementById(email);
	   
	   if(address.value=='') {
		  address.className='im_extvalid im_errorValid'; 
		  return false;
	   }
	   else{
		 address.className='im_extvalid'; 
	   	  return true;
	   }
	}
