		/*<![CDATA[*/(
		function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:235},j);this.filter('textarea').each(function(){var c=a(this).css({resize:'none','overflow-y':'hidden'}),k=c.height(),f=(function(){var l=['height','width','lineHeight','textDecoration','letterSpacing'],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr('id').removeAttr('name').css({position:'absolute',top:0,left:-9999}).css(h).insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css('overflow-y','');return}b.onResize.call(this);b.animate&&c.css('display')==='block'?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind('.dynSiz').bind('keyup.dynSiz',g).bind('keydown.dynSiz',g).bind('change.dynSiz',g)});return this}})(jQuery);$('textarea#pro_textarea').autoResize();/*]]>*/

var upload=1;
		
function getHTTPObject() 
{
	var xmlhttp;
	if(window.XMLHttpRequest)
	{
		xmlhttp=new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if(!xmlhttp) {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	return xmlhttp;
}
var http=getHTTPObject();		
		
		
function show_type(opt) {
	/* to change navigation */
	document.getElementById('et_img').src = (opt == 'e') ? "images/enter-txt-ovr.jpg" : "images/enter-txt-nrl.jpg";
	document.getElementById('up_img').src = (opt == 'up') ? "images/upl-file-ovr.jpg" : "images/upl-file-nrl.jpg";
	document.getElementById('now_img').src = (opt == 'now') ? "images/no-of-wrds-ovr.jpg" : "images/no-of-wrds-nrl.jpg";	
	/* to select corresponding div */
	document.getElementById('enter_text').style.display = (opt == 'e') ? "block" : "none";
	document.getElementById('upload_files').style.display = (opt == 'up') ? "block" : "none";
	document.getElementById('no_words').style.display = (opt == 'now') ? "block" : "none";

}

function showtar(orgId) {
	if(orgId == -1){
		window.location = "morelanguages.php";
	}else{
		var tar_dump = document.getElementById('tar_val_temp').value.split('|@|');
		var tar_names_temp = tar_dump[0].split('[~]');
		var tar_values_temp = tar_dump[1].split('[~]');	
		var str = '<select name="tar" id="tar" size="1" onchange="checkService(this.value)">';
		 str += '<option value="0">Select Language</option>';	
		var data = '';
		for(i=0; i<(tar_names_temp.length-1); i++) {
			if((i+1) == orgId) {
				var tar_name_array = tar_names_temp[i].split('|~|');
				var tar_values_array = tar_values_temp[i].split('|~|');			
				for(j=0; j<(tar_name_array.length-1); j++) {
					data += '<option value="'+tar_values_array[j]+'">'+tar_name_array[j]+'</option>';	
				}
			}
		}
		if(data)
			 str += data;
	
		str += '<option value="-1" style="color:#351252;font-weight:bold;">More languages available </option>';
		str += '</select>';
		document.getElementById('show').innerHTML = str;
	}
}

function selectService(sid) {
	var selObj = document.getElementById('moreService');
	var cnt = 0;
	for(i=0; i<selObj.options.length; i++) {
		var selVal = selObj.options[i].value.split('|~|');
		if(selVal[1] == sid){
			selObj.options[i].selected=true;
		}
		else {	
			selObj.options[i].selected=false;
		}
	}	
}

function checkServiceForProvider(serId) {

	var tar_arr = serId.split('|~|');
	var check_cond = tar_arr[0].split(',');
	if(check_cond[0]<check_cond[2] && check_cond[1]<check_cond[3]) {
		//do nothing
	} else {
		alert("At the moment not enough service providers are available to provide you this service. Come back later or choose another service");
		var selObj = document.getElementById('moreService');
		for(i=0; i<selObj.options.length; i++) {
			if(selObj.options[i].value == serId){
				selObj.options[i].selected=false;
			}
		}
	}
}

function checkService(tarId) {
	if(tarId == -1){
		window.location = "index1.php?val="+document.getElementById('orgName').value;
	}else{

	var tar_arr = tarId.split(',');
	var check_cond = tar_arr[0].split('#');
	selectService(tar_arr[1]);
	/*if(check_cond[0]<check_cond[1] && check_cond[2]<check_cond[3]) {
		selectService(tar_arr[1]);
	} else {
		alert("At the moment not enough service providers are available to provide you this service. Come back later or choose another service");
	}*/
	}
}

function showHide(id) {
	var set = 0;
	if(id=='more-service'){
		if(!checkInitial()) {
			set=1;
		} else if(getDocTot()>1) {
			alert("you cannot able to upload multiple documents for multiple services");
			set = 2;
		}
	}
	if(set==0) {
		document.getElementById(id).style.display = (document.getElementById(id).style.display == 'block') ? 'none' : 'block';
	}
}

function nowCheck() {
	if(isNaN(document.getElementById('tot_now').value))  {
		alert("Please enter only numbers in Number of words column");
		document.getElementById('tot_now').focus();
		return false;
		
	}
}


function removeSpecial(val) {
	var iChars3 = Array("~","`",".","_","!","@","#","$","%","^","*","(",")","+","=","–","-","[","]","\\","\'",";","/","{","}","|","\"",":","<",">","?");
	for(i=0; i<iChars3.length; i++) {
		var val = val.split(iChars3[i]);
  		val = val.join('');
	}
	//alert(val);
	
	return val;
}

function Trim(nStr){return nStr.replace(/(^\s*)|(\s*$)/g, "");}

function  countWord() {
	if(document.getElementById('pro_textarea')) {
		var err = 0;
		var now = 0;
		var val = removeSpecial(document.getElementById("pro_textarea").value);
		var arr = val.split('\n');
		var arr1 = val.split(' ');
		if(arr.length>0) {
			for(i=0; i<arr.length; i++) {
				var arr2 = arr[i].split(" ");
				for(j=0; j<arr2.length; j++) {
					if(Trim(arr2[j])) {
						now++;
						err=0;
					} else if(now==0) {
						err=2;
					}
				}
			}
	
		} else if(arr1.length>0) { // for the text which does not have line breaks
			for(j=0; j<arr1.length; j++) {
				if(Trim(arr1[j])) {
					now++;
					err=0;
				} else if(now==0) {
					err=2;
				}
			}
		} else  {
			err=1;
		}	
		if(err==0) {
			document.getElementById("showWordsDiv").style.display="block";
			document.getElementById("showWords").innerHTML = now;
			document.getElementById("pro_text_now").value = now;
		} else {
			document.getElementById("showWordsDiv").style.display="none";
			document.getElementById("showWords").innerHTML = "";
			document.getElementById("pro_text_now").value = 0;		
		}
	}
}


function addupload() {
	if(checkInitial()) {
		upload++;
		var ni = document.getElementById('div_files');
		var newdiv = document.createElement('div');
		var divIdName = 'upload'+upload;
		newdiv.setAttribute('id',divIdName);
	  newdiv.innerHTML = '<font id="browse'+upload+'"><input name="txtdocument'+upload+'" type="file" onchange="calltype(this.value,'+upload+',0);"  class="fileuploader" 		id="txtdocument'+upload+'" size="20" /><br /><a href="#" class="remove_file" onclick="removeFile('+upload+');">Remove</a><br /><font id="div_txt_'+upload+'"></font></font>';
		ni.appendChild(newdiv);
		document.getElementById('delTableId').value = upload;
		
	}
}


function checkCond(sid) {
	if(getTotSerSel()>1) {
		document.getElementById('addMore').innerHTML='';
		removeAll();
		checkServiceForProvider(sid);
	} else {
		checkServiceForProvider(sid);
		document.getElementById('addMore').innerHTML='<a href="javascript:addupload();" class="smalllink_lightpurple" id="add_more" style="padding-left:2px;">Add More Documents</a>';
	}
}

function removeAll() {
	for(i=2; i<upload; i++) {
		var d = document.getElementById('div_files');
		var divNum = 'upload'+i;
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
	}

}


function checkInitial() {
	if ((document.getElementById('orgName').value=='0') || (document.getElementById('tar').value=='0')) 	{
		alert("Please select original and target language before uploading the document");
		return false;
	} else {
		return true;
	}
}


function getTotSerSel() {
	var selObj = document.getElementById('moreService');
	var cnt = 0;
	for(i=0; i<selObj.options.length; i++) {
		if(selObj.options[i].selected)
			cnt++
	}
	return cnt;
}


function getServiceID() {
	var selObj = document.getElementById('moreService');
	var sid='';
	var cnt = 0;
	for(i=0; i<selObj.options.length; i++) {
		if(selObj.options[i].selected) {
			 //sid += (sid=='') ? selObj.options[i].value :  ','+selObj.options[i].value;  // use this for new pages
			 var serVal = selObj.options[i].value.split("|~|");
			 sid += serVal[1]+',';  // only for old pages
		}
	}
	return sid;
}

function removeFile(file_id) {
	var d = document.getElementById('div_files');
	var divNum = 'upload'+file_id;
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
	document.getElementById('delTableId').value = document.getElementById('delTableId').value-1;
}


function getDocTot() {
	var cnt=0;
	for(i=1; i<=upload; i++) {
		if(document.getElementById('upload'+i)) {
			if(document.getElementById('txtdocument'+i)) {
				if(document.getElementById('txtdocument'+i).value!='') {
					cnt++;
				}
			}
		}
	}
	
	return cnt;
	
}

function calltype(file,id,chk) {
	if(!checkInitial()) {
		return false;
	} else if(getDocTot()>1 && getTotSerSel()>1) {
		alert("you cannot able to upload multiple documents for multiple services");
		removeFile(id);
		return false;
	} else {
		var type_array = file.split('.');
		var type = type_array[type_array.length-1].toLowerCase();
		if(type == 'doc' || type == 'docx' || type == 'xls' || type == 'xlsx' || type == 'ppt' || type == 'pptx' || type == 'txt' || type == 'pdf' || type == 'jpg' || type == 'png' || type == 'gif'|| type == 'jpeg' || type == 'xml' || type == 'zip') {
			if(type!='txt') { 
				if(chk==0) {
					var word = '<div class="upload-enter-word"><div class="upload-text-part"><div class="upload-enter-text"> Enter the total number of words</div><div class="upload-word-text"><input type="text" size="2" maxlength="10" name="txt[]" id="txt'+id+'" class="txtboxsize"></div></div><div class="upload-radio-part"><div class="upload-radio-text">Display document to potential translators</div><div class="upload-radio-option"><input type="radio" size="2" maxlength="10" name="docstatus'+id+'" id="docstatus'+id+'"  value="1" checked>Yes <br><input type="radio" size="2" maxlength="10" name="docstatus'+id+'" id="docstatus'+id+'"  value="2" >No </div></div></div>'
					document.getElementById('div_txt_'+id).innerHTML = word;
				}
					return true;
			} else {
				if(chk==0) {
					document.getElementById('div_txt_'+id).innerHTML = '';	
				}
				return true;
			}
			
		} else {
			alert("Tomedes accepts files in the following formats: Microsoft Word (.doc), PDF files (.pdf), Microsoft Excel (.xls), Microsoft PowerPoint(.ppt), text files (.txt), image files(.jpg,.jpeg,.gif,.png), xml file(.xml), zip files(.zip) and rich text (.rtf) files. If your document does not fit one of these types, please contact us.");	
			var set = '<font id="browse'+id+'"><input name="txtdocument'+id+'" type="file" onchange="calltype(this.value,'+id+',0);"  class="fileuploader" id="txtdocument'+id+'" size="20" /><br /><font id="div_txt_'+id+'"></font>';
			if(id!=1)
				set+='<a href="#" class="remove_file" onclick="removeFile('+id+');">remove</a></font>';

			document.getElementById('browse'+id).innerHTML = set;
			return false;
		}
	}
}


function checkAllTypes() {
 	var val = 0;
	for(var i= 1; i<upload; i++) {
		if(document.getElementById('upload'+i)) {
			if(document.getElementById('txtdocument'+i)) {
				if(document.getElementById('txtdocument'+i).value!='') {
					if(!calltype(document.getElementById('txtdocument'+i).value,i,'1')) {
						val=i;
					}
				}
			}
		}
	}
	return val;
}


function checkDocTypes() {
	show_type('up');
	for(var i= 1; i<=upload; i++) {
		if(document.getElementById('upload'+i)) {
			if(document.getElementById('txtdocument'+i)) {
				if(document.getElementById('txtdocument'+i).value!='') {
					var type_array = document.getElementById('txtdocument'+i).value.split('.');					
					var type = type_array[type_array.length-1].toLowerCase();
					if(type!='txt') {
						if(document.getElementById('txt'+i).value == '') {
							alert("Please enter number of words");
							document.getElementById('txt'+i).focus();
							return true;
						} else if(document.getElementById('txt'+i).value != '') {
							var num = document.getElementById('txt'+i).value.split('.');
							if(isNaN(document.getElementById('txt'+i).value)) {
								alert("Please enter only decimal value");
								document.getElementById('txt'+i).focus();
								return true;
							} else if(num.length > 1) {
								alert("Please enter only decimal values"); 
								document.getElementById('txt'+i).focus();
								return true;
							}
						} 
					}
				}
			}
		}
	}
	return false;
}

function checkEmail(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm)){
		return (true)
	}
	else {
		return false;
	}
}


function validateRequest() {
	if(Trim(document.getElementById('txtrequest').value) == '') {
		alert("Please enter language pair you need");
		document.getElementById('txtrequest').focus();
		return false;
	}
	else if(!checkEmail(document.getElementById('txtemail').value)) {
		alert("Please enter a valid email address");
		document.getElementById('txtemail').focus();		
		return false;
	}else
	{
		var url="insert_servicerequest.php";
		
		 url=url+"?sname="+document.getElementById('txtrequest').value+'&eid='+document.getElementById('txtemail').value;
		http.open("GET", url, true); 
		 http.onreadystatechange = function()
		 {
			if (http.readyState == 4) 
			{ 
			   if(http.status==200) 
			   { 
				 var results=http.responseText;
				 if(Trim(results.toLowerCase())=='service request sent successfully')
				  {
					document.getElementById('txtrequest').value="";  
					document.getElementById('txtemail').value="";  
				  }
				  document.getElementById("requestform").style.display = "none";
				  document.getElementById("msg").style.display = "block";
				 document.getElementById('msg').innerHTML= "<b><font color='red'>" + results + "</font></b>"; 
			
			   } 
			 } 
		  }
	
	   http.send(null);  
		}		
}


function quoteForm() {
	postpage=0;
	if(document.getElementById('orgName').value=='0') {
		alert("Please Choose Original Language.");
		document.getElementById('orgName').focus();
		return false;
	}
	if(document.getElementById('tar').value=='0') {
		alert("Please Choose Target Language.");
		document.getElementById('tar').focus();
		return false;
	}
	if(document.getElementById('categoryName').value=='0') {
		alert("Please Choose Service.");
		document.getElementById('categoryName').focus();
		return false;
	}
	if(document.getElementById('subcategory').value=='0') {
		alert("Please Choose Subject Field.");
		document.getElementById('subcategory').focus();
		return false;
	}
	if(document.getElementById('pro_textarea').value=='' && getDocTot()==0 && document.getElementById('tot_now').value=='') {
		alert("Please select only one of the given options.");
		return false;
	}
	if((document.getElementById('pro_textarea').value!='' && getDocTot()>0) || (document.getElementById('pro_textarea').value!='' && document.getElementById('tot_now').value!='') || (getDocTot()>0 && document.getElementById('tot_now').value!='')) {
		alert("Please select only one of the given options.");
		return false;
	}
	
	if(document.getElementById('pro_textarea').value!='') {
		show_type('e');
		if(document.getElementById('pro_text_now').value<=0) {
			alert("Please enter the text to proceed forward");
			document.getElementById('pro_textarea').focus();
		} else {
			postpage = 1;
		}
	}
	if(getDocTot()>0) {
		var id = checkAllTypes();
		if(getTotSerSel()>1 && getDocTot()>1){
			alert("you cannot able to upload multiple documents for multiple services");
			return false;
		} else if(id>0) {
			alert("Tomedes accepts files in the following formats: Microsoft Word (.doc), PDF files (.pdf), Microsoft Excel (.xls), Microsoft PowerPoint(.ppt), text files (.txt) and rich text (.rtf) files. If your document does not fit one of these types, please contact us.");
			document.getElementById('txtdocument'+id).focus();
			return false;
		}  else if(checkDocTypes()) {
			return false;
		}else {
			postpage=1;
		}
		
	}
	if(document.getElementById('tot_now').value!='') {
		show_type('now');		
		if(document.getElementById('tot_now').value>0) {
			postpage=2;
		} else {
			alert("Please enter only numbers in Number of words column");
			document.getElementById('tot_now').focus();
			return false;
		}
		
	}
	var textdoc = "txtdocument";	
var doclen=document.getElementById('delTableId').value;
var varArray1 =  doclen
//alert(doclen);
if (doclen >=2)
{
//alert("test1");
	for(var i = 2; i <= doclen; i++)
	{
		var chck1=0;
//alert("test2");
		for(k=0; k<varArray1.length; k++)
		{
			//if(i==varArray1[k])
				//chck1++;
		}
//alert("test3");alert(chck1);
		if(chck1==0)
		{
			var var1=textdoc+i;
//alert("test4");
			if (document.getElementById(var1).value != "")
			{
//alert("test5");
				for (var ck = 1; ck < i; ck++)
				{
					var var2 = textdoc+ck;
					//alert(document.getElementById(var1).value + "-" + document.getElementById(var2).value);
					if((document.getElementById(var1).value == document.getElementById(var2).value) && (document.getElementById(var2).value != ""))	
					{
						alert("You have uploaded the same files. Please upload different files");
						return false;
					}
				}
			}
		}		
	}	
}
	document.getElementById('service_id_val').value = getServiceID();
	document.getElementById('service').value =document.getElementById('service_id_val').value ;
	var totValue = (getTotSerSel()>getDocTot()) ? getTotSerSel() : getDocTot();
	document.getElementById('countArray').value = 'docCount#'+getDocTot()+',serCount#'+getTotSerSel()+',totVal#'+totValue;
	document.frm_index.method = "post";
	document.frm_index.action= (postpage==1) ? "doc_quote.php" : "now_quote.php";	 
	document.frm_index.submit();
} 
//function showsubcate(val){
	var xmlhttp;


function GetXmlHttpObject_new(){
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}


function stateChangedlast_new(){
	if (xmlhttp.readyState==4){
		response=xmlhttp.responseText;
		document.getElementById("show-subcategory").innerHTML = response;
	}
}


function showsubcate(val)
{ 
	xmlhttp=GetXmlHttpObject_new();
	if (xmlhttp==null){
		alert ("Your browser does not support XMLHTTP!");
		return;
	}
	var url="getsubcategory.php";
	url=url+"?val="+val;
	url=url+"&random="+Math.random();
	xmlhttp.onreadystatechange=stateChangedlast_new;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
//}

