// JavaScript Document

// etc
function display_change(div) {
document.getElementById(div).style.display = (document.getElementById(div).style.display == "block") ? "none" : "block";        
}

function AutoResize(id, MaxWidth) {
	if(document.getElementById(id).width > document.getElementById(id).height) {
		if(document.getElementById(id).width > MaxWidth) {
		  document.getElementById(id).height=document.getElementById(id).height*MaxWidth/document.getElementById(id).width;
		  document.getElementById(id).width=MaxWidth;
		}
	}
	else if(document.getElementById(id).width < document.getElementById(id).height) {
		if(document.getElementById(id).height > MaxWidth) {
		  document.getElementById(id).width=document.getElementById(id).width*MaxWidth/document.getElementById(id).height;
		  document.getElementById(id).height=MaxWidth;		  
		}
	}
	else {
		if(document.getElementById(id).width > MaxWidth) {
		  document.getElementById(id).height=document.getElementById(id).height*MaxWidth/document.getElementById(id).width;
		  document.getElementById(id).width=MaxWidth;		  
		}
		else if(document.getElementById(id).height > MaxWidth) {
		  document.getElementById(id).width=document.getElementById(id).width*MaxWidth/document.getElementById(id).height;
		  document.getElementById(id).height=MaxWidth;		  
		}				
	}
}

function AutoResize2(id, MaxWidth, MaxHeight) {
	if(document.getElementById(id).width > MaxWidth) {
	  document.getElementById(id).height=document.getElementById(id).height*MaxWidth/document.getElementById(id).width;
	  document.getElementById(id).width=MaxWidth;
	}
	if(document.getElementById(id).height > MaxHeight) {
	  document.getElementById(id).width=document.getElementById(id).width*MaxHeight/document.getElementById(id).height;
	  document.getElementById(id).height=MaxHeight;	  
	}
}

function check_string(textareaid, maxlong, checkstnowid) {
	var text_length = document.getElementById(textareaid).value.length ;
	if(text_length > maxlong-1){ 
		document.getElementById(textareaid).value = document.getElementById(textareaid).value.substr(0, maxlong-1); 
	} 
	
	document.getElementById(checkstnowid).innerHTML  = '<span class=\'info\'>' + text_length + '\/' + maxlong + 'Byte<\/span>' ;
}

// form check
function logincheck()
{
    if (document.getElementById('loginemail').value=="")
    {
        alert("enter id"); 
        document.getElementById('loginemail').select();
        document.getElementById('loginemail').focus();
        return false;
    }

    if (document.getElementById('loginpword').value=="")
    {
        alert("enter password"); 
        document.getElementById('loginpword').select();
        document.getElementById('loginpword').focus();
        return false;
    }
    return true;
}

function register_check() 
{

	if (document.getElementById('agree') != null) {
	
		if (!document.getElementById('agree').checked) {		
			alert("agree our policy"); 
			return false;
		}
		
	}
	
	// email check
    if (document.getElementById('email_pre').value=="")
    {
        alert("enter correct e-mail"); 
        document.getElementById('email_pre').select();
        document.getElementById('email_pre').focus();
        return false;
    }
	else {
	  invalidChars=' #$%^&*()=+/:,;';
	  Email=document.getElementById('email_pre').value;	
	  for (i=0;i<invalidChars.length;i++) {
		  badChar=invalidChars.charAt(i);
		  if (Email.indexOf(badChar,0)>-1) {
			   alert('do not use #$%^&*()=+/:,;');
			   return false;					
		  }
	  }
		
	  atPos=Email.indexOf('@',1);
	  if (atPos==-1) {
			   alert('use correct e-mail');
			   return false;					
		  }
		
	  if (Email.indexOf('@',atPos+1)>-1) {
			   alert('use correct e-mail');
			   return false;					
		  }
		
	  periodPos=Email.indexOf('.',atPos);
		
	  if (periodPos==-1) {
			   alert('use correct e-mail');
			   return false;					
		  }
		
	  if (periodPos+3>Email.length) {
			   alert('use correct e-mail');
			   return false;					
		  }
	}	
	
	// password check
	if (document.getElementById('ppword') == null) {
		if (document.getElementById('pword').value=="")
		{
			alert("enter password"); 
			document.getElementById('pword').select();
			document.getElementById('pword').focus();
			return false;
		}
		else if (document.getElementById('pword2').value=="")
		{
			alert("enter re-enter password"); 
			document.getElementById('pword2').select();
			document.getElementById('pword2').focus();
			return false;
		}
		else
		{
			pword=document.getElementById('pword').value;
			if(pword.length < 6) {
			   alert('Minimum password of 6 characters in length');
			   return false;
			}	  
			if(pword != document.getElementById('pword2').value) {
			   alert('check re-entered password');
			   return false;
			}	  			  
		}
	}
	else {
		if (document.getElementById('ppword').value=="")
		{
			alert("enter present password"); 
			document.getElementById('ppword').select();
			document.getElementById('ppword').focus();
			return false;
		}
		else
		{
			ppword=document.getElementById('ppword').value;
			if(ppword.length < 6) {
			   alert('Minimum present password of 6 characters in length');
			   return false;
			}
			if(document.getElementById('pword').value != '') {
				if(document.getElementById('pword').value.length < 6) {
				   alert('Minimum password of 6 characters in length');
				   return false;
				}				
			}
			if(document.getElementById('pword').value != document.getElementById('pword2').value) {
			   alert('check re-entered password');
			   return false;
			}	  			  
		}
	}	
	
	// sname check
    if (document.getElementById('sname').value=="")
    {
        alert("enter screen name"); 
        document.getElementById('sname').select();
        document.getElementById('sname').focus();
        return false;
    }    
	
	// ethnic check
    if (document.getElementById('ethnic').value=="")
    {
        alert("select your ethnic"); 
        return false;
    } 
	
	return true;
}

function form_check()
{
	
    if (document.getElementById('subject') != null && document.getElementById('subject').value == ''){
		alert("input Title");
		document.getElementById('subject').focus();
        return false;
	}
	
    if (document.getElementById('shownattxt') != null && document.getElementById('shownattxt').value == ''){
		alert("input AD showon at");
		document.getElementById('shownattxt').focus();
        return false;
	}	

    if (document.getElementById('cname') != null && document.getElementById('cname').value == ''){
		alert("input company name");
		document.getElementById('cname').focus();
        return false;
	}
	
    if (document.getElementById('yname') != null && document.getElementById('yname').value == ''){
		alert("input your name");
		document.getElementById('yname').focus();
        return false;
	}	

    if (document.getElementById('phone') != null && document.getElementById('phone').value == ''){
		alert("input your phone");
		document.getElementById('phone').focus();
        return false;
	}	
	
    if (document.getElementById('email') != null && document.getElementById('email').value == ''){
		alert("input your e-mail");
		document.getElementById('email').focus();
        return false;
	}	
	
    if (document.getElementById('desc') != null && document.getElementById('desc').value == ''){
		alert("input description");
		document.getElementById('desc').focus();
        return false;
	}	
	
    if (document.getElementById('classic') != null && document.getElementById('classic').value == ''){
		alert("input Classification");
		document.getElementById('classic').focus();
        return false;
	}	
	
    if (document.getElementById('media') != null && document.getElementById('media').value == ''){
		alert("input media");
		document.getElementById('media').focus();
        return false;
	}	
	
    if (document.getElementById('srep') != null && document.getElementById('srep').value == ''){
		alert("input Sales Rep");
		document.getElementById('srep').focus();
        return false;
	}	
	
    if (document.getElementById('rprice') != null && document.getElementById('rprice').value == ''){
		alert("input Regular");
		document.getElementById('rprice').focus();
        return false;
	}
	
    if (document.getElementById('oprice') != null && document.getElementById('oprice').value == ''){
		alert("input your price");
		document.getElementById('oprice').focus();
        return false;
	}	
	
    if (document.getElementById('bname') != null && document.getElementById('bname').value == ''){
		alert("input business name");
		document.getElementById('bname').focus();
        return false;
	}
	
    if (document.getElementById('aprice') != null && document.getElementById('aprice').value == ''){
		alert("input asking price");
		document.getElementById('aprice').focus();
        return false;
	}	
	
    if (document.getElementById('revenue') != null && document.getElementById('revenue').value == ''){
		alert("input Sale revenue");
		document.getElementById('revenue').focus();
        return false;
	}	
	
    if (document.getElementById('employees') != null && document.getElementById('employees').value == ''){
		alert("input employees");
		document.getElementById('employees').focus();
        return false;
	}
	
    if (document.getElementById('blocat') != null && document.getElementById('blocat').value == ''){
		alert("input business location");
		document.getElementById('blocat').focus();
        return false;
	}

    if (document.getElementById('contents1') != null && document.getElementById('contents1').value == ''){
		alert("input contents");
		document.getElementById('contents1').focus();
        return false;
	}
	
    if (document.getElementById('aboutus') != null && document.getElementById('aboutus').value == ''){
		alert("input aboutus");
		document.getElementById('aboutus').focus();
        return false;
	}
	
    if (document.getElementById('product') != null && document.getElementById('product').value == ''){
		alert("input product");
		document.getElementById('product').focus();
        return false;
	}
	
    if (document.getElementById('buy') != null && document.getElementById('buy').value == ''){
		alert("input buy link");
		document.getElementById('buy').focus();
        return false;
	}	
	
    if (document.getElementById('add1') != null && document.getElementById('add1').value == ''){
		alert("input address");
		document.getElementById('add1').focus();
        return false;
	}	
	
    if (document.getElementById('add2') != null && document.getElementById('add2').value == ''){
		alert("input city");
		document.getElementById('add2').focus();
        return false;
	}	
	
    if (document.getElementById('add3') != null && document.getElementById('add3').value == ''){
		alert("input state");
		document.getElementById('add3').focus();
        return false;
	}	
	
    if (document.getElementById('add4') != null && document.getElementById('add4').value == ''){
		alert("input zip");
		document.getElementById('add4').focus();
        return false;
	}	
	
    if (document.getElementById('sprice') != null && document.getElementById('sprice').value == ''){
		alert("input sale price");
		document.getElementById('sprice').focus();
        return false;
	}	
	
    if (document.getElementById('seller') != null && document.getElementById('seller').value == ''){
		alert("input seller");
		document.getElementById('seller').focus();
        return false;
	}	
	
    if (document.getElementById('intro') != null && document.getElementById('intro').value == ''){
		alert("input introduction");
		document.getElementById('intro').focus();
        return false;
	}	
	
    if (document.getElementById('desc1') != null && document.getElementById('desc1').value == ''){
		alert("input description 1");
		document.getElementById('desc1').focus();
        return false;
	}	
	
    if (document.getElementById('notice') != null && document.getElementById('notice').value == ''){
		alert("input notice");
		document.getElementById('notice').focus();
        return false;
	}	
	
    if (document.getElementById('femail') != null && document.getElementById('femail').value == ''){
		alert("input e-mail");
		document.getElementById('femail').focus();
        return false;
	}
	
    if (document.getElementById('telnum') != null && document.getElementById('telnum').value == ''){
		alert("input phone");
		document.getElementById('telnum').focus();
        return false;
	}
	
    if (document.getElementById('bdesc') != null && document.getElementById('bdesc').value == ''){
		alert("input business description");
		document.getElementById('bdesc').focus();
        return false;
	}	
	
    if (document.getElementById('rdetail') != null && document.getElementById('rdetail').value == ''){
		alert("input request in detail");
		document.getElementById('rdetail').focus();
        return false;
	}	
	
	return true;
}

// layout
function show_change(div1, div2){
	if (document.getElementById(div2)){
		document.getElementById(div1).style.display = "none";
		document.getElementById(div2).style.display = "block";
	}
}
function show_change_triple(div1, div2, div3){
	document.getElementById(div3).style.display = "block";
	document.getElementById(div1).style.display = "none";
	document.getElementById(div2).style.display = "none";
}

// DOM
function email_check(str) { 
	emailchk = document.createElement("script");
	emailchk.src = 'email_check.php?' + str;
	document.body.appendChild(emailchk);
}

function shortcut_check(str) { 
	if(document.getElementById("shortcutcheck")!=null){
		var shortcutcheck = document.getElementById("shortcutcheck");
		shortcutcheck.parentNode.removeChild(shortcutcheck);
	}	
	shortcutcheck = document.createElement("script");
	shortcutcheck.src = '/common/shortcut_check.php?' + str +'\&seq='+document.getElementById('seq').value;
	document.body.appendChild(shortcutcheck);
}

function select_cat1(level) {
	if(document.getElementById("select_cat1")!=null){
		var select_cat1 = document.getElementById("select_cat1");
		select_cat1.parentNode.removeChild(select_cat1);
	}
	select_cat1 = document.createElement("script");	
	select_cat1.setAttribute("id", "select_cat1");	
	
	select_cat1.src = '/common/select_category.php?cat=' + document.getElementById('category').value + '&level=' + level ;		
	document.body.appendChild(select_cat1);
}

function select_cat(div_num, cat, show_type ) {
	if (div_num == "1"){
		if(document.getElementById("sel_id1")!=null){
			var sel_id1 = document.getElementById("sel_id1");
			sel_id1.parentNode.removeChild(sel_id1);
		}		
		sel_id1 = document.createElement("script");	
		sel_id1.setAttribute("id", "sel_id1");		
		sel_id1.src = '/common/select_category_new.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;		
		document.body.appendChild(sel_id1);
	}
	else if (div_num == "2"){
		if(document.getElementById("sel_id2")!=null){
			var sel_id2 = document.getElementById("sel_id2");
			sel_id2.parentNode.removeChild(sel_id2);
		}		
		sel_id2 = document.createElement("script");	
		sel_id2.setAttribute("id", "sel_id2");		
		sel_id2.src = '/common/select_category_new.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;			
		document.body.appendChild(sel_id2);	
	}
	else if (div_num == "3"){
		if(document.getElementById("sel_id3")!=null){
			var sel_id3 = document.getElementById("sel_id3");
			sel_id3.parentNode.removeChild(sel_id3);
		}		
		sel_id3 = document.createElement("script");	
		sel_id3.setAttribute("id", "sel_id3");		
		sel_id3.src = '/common/select_category_new.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;			
		document.body.appendChild(sel_id3);		
	}
	else if (div_num == "4"){
		if(document.getElementById("sel_id4")!=null){
			var sel_id4 = document.getElementById("sel_id4");
			sel_id4.parentNode.removeChild(sel_id4);
		}		
		sel_id4 = document.createElement("script");	
		sel_id4.setAttribute("id", "sel_id4");		
		sel_id4.src = '/common/select_category_new.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;			
		document.body.appendChild(sel_id4);		
	}
}

function select_cat_admin(div_num, cat, show_type ) {
	if (div_num == "1"){
		if(document.getElementById("sel_id1")!=null){
			var sel_id1 = document.getElementById("sel_id1");
			sel_id1.parentNode.removeChild(sel_id1);
		}		
		sel_id1 = document.createElement("script");	
		sel_id1.setAttribute("id", "sel_id1");		
		sel_id1.src = '/common/select_category_admin.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;		
		document.body.appendChild(sel_id1);
	}
	else if (div_num == "2"){
		if(document.getElementById("sel_id2")!=null){
			var sel_id2 = document.getElementById("sel_id2");
			sel_id2.parentNode.removeChild(sel_id2);
		}		
		sel_id2 = document.createElement("script");	
		sel_id2.setAttribute("id", "sel_id2");		
		sel_id2.src = '/common/select_category_admin.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;			
		document.body.appendChild(sel_id2);	
	}
	else if (div_num == "3"){
		if(document.getElementById("sel_id3")!=null){
			var sel_id3 = document.getElementById("sel_id3");
			sel_id3.parentNode.removeChild(sel_id3);
		}		
		sel_id3 = document.createElement("script");	
		sel_id3.setAttribute("id", "sel_id3");		
		sel_id3.src = '/common/select_category_admin.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;			
		document.body.appendChild(sel_id3);		
	}
	else if (div_num == "4"){
		if(document.getElementById("sel_id4")!=null){
			var sel_id4 = document.getElementById("sel_id4");
			sel_id4.parentNode.removeChild(sel_id4);
		}		
		sel_id4 = document.createElement("script");	
		sel_id4.setAttribute("id", "sel_id4");		
		sel_id4.src = '/common/select_category_admin.php?dn=' + +div_num + '&cat=' + cat + '&st=' + show_type ;			
		document.body.appendChild(sel_id4);		
	}
}

function sel_CO_board(cb_seq) {
	sel_cb = document.createElement("script");	
	//sel_CO_board_child.setAttribute("id", "sel_CO_board_child");		
	sel_cb.src = '/common/sel_CO_board.php?seq=' + cb_seq ;		
	document.body.appendChild(sel_cb);	

}

function mod_CO_board() {
	c_seq = document.getElementById('c_seq').value;
	cb_seq = document.getElementById('cb_sel').value;
	board_n = document.getElementById('board_n').value;
	board_t = document.getElementById('board_t').value;
	board_f = document.getElementById('board_f').value;	
	if(document.getElementById("mod_cb")!=null){
		var mod_cb = document.getElementById("mod_cb");
		mod_cb.parentNode.removeChild(mod_cb);
	}	
	mod_cb = document.createElement("script");	
	//sel_CO_board_child.setAttribute("id", "sel_CO_board_child");		
	mod_cb.src = '/common/mod_CO_board.php?seq=' + cb_seq + '&c_seq=' + c_seq + '&n=' + board_n + '&t=' + board_t + '&f=' + board_f  ;		
	document.body.appendChild(mod_cb);	
}

function delete_CO_board() {
	c_seq = document.getElementById('c_seq').value;
	cb_seq = document.getElementById('cb_sel').value;
	if(document.getElementById("delete_cb")!=null){
		var delete_cb = document.getElementById("delete_cb");
		delete_cb.parentNode.removeChild(delete_cb);
	}	
	delete_cb = document.createElement("script");		
	delete_cb.src = '/common/delete_CO_board.php?seq=' + cb_seq + '&c_seq=' + c_seq  ;		
	document.body.appendChild(delete_cb);	
}

function updown_CO_board(mode) {
	c_seq = document.getElementById('c_seq').value;
	cb_seq = document.getElementById('cb_sel').value;
	if(document.getElementById("updown_cb")!=null){
		var updown_cb = document.getElementById("updown_cb");
		updown_cb.parentNode.removeChild(updown_cb);
	}	
	updown_cb = document.createElement("script");		
	updown_cb.src = '/common/updown_CO_board.php?seq=' + cb_seq + '&c_seq=' + c_seq + '&mode=' + mode  ;		
	document.body.appendChild(updown_cb);	

}
